Data Modeling Considerations for MongoDB Applications - MongoDB Manual 2.4.1 - 0 views
-
Embedding¶ To de-normalize data, store two related pieces of data in a single document. Operations within a document are less expensive for the server than operations that involve multiple documents. In general, use embedded data models when: you have “contains” relationships between entities. See Model Embedded One-to-One Relationships Between Documents. you have one-to-many relationships where the “many” objects always appear with or are viewed in the context of their parent documents. See Model Embedded One-to-Many Relationships Between Documents. Embedding provides the following benefits: generally better performance for read operations. the ability to request and retrieve related data in a single database operation.
-
Referencing¶ To normalize data, store references between two documents to indicate a relationship between the data represented in each document. In general, use normalized data models: when embedding would result in duplication of data but would not provide sufficient read performance advantages to outweigh the implications of the duplication. to represent more complex many-to-many relationships. to model large hierarchical data sets. See Model Tree Structures in MongoDB. Referencing provides more flexibility than embedding; however, to resolve the references, client-side applications must issue follow-up queries. In other words, using references requires more roundtrips to the server.