A MongoDB document is a BSON record of field-value pairs representing a stored data object. Documents reside in collections, which reside in databases. Documents in one collection may use different fields or types, enabling dynamic schemas. section 17.1
Table 17.1 Compared terminology: RDBMS vs. MongoDB (view table figure)
Use the terminology comparison to translate between MongoDB and relational database concepts: collection/table, document/row, and field/column. section 17.1
A user document
A stored user document can contain an identifier, username, personal names, registration date, email, numeric level, active flag, and mapped Java class name. MongoDB Compass can filter it with {"username":"john"}. section 17.1
Design and persistence implications include:
- Treat fields as document properties rather than assuming every document shares one fixed relational schema. section 17.1
- Reference another document with a DBRef containing the target collection and identifier; embedding documents is not supported by Spring Data MongoDB. section 17.5
- Persist or delete referenced documents explicitly because save and delete operations do not cascade between documents. section 17.5
