Reputation: 982
Im looking to use MongoDB for my database implementation. Why would you want to embded a document insode a document?
Upvotes: 1
Views: 317
Reputation:
In simple terms, embed if its NOT a top level object, if it does NOT have complex relationships, if there will be a lot of duplicate data if you do NOT embed, and if your documents become bigger then a few megabytes.
Taken from the MongoDB site: http://www.mongodb.org/display/DOCS/Schema+Design
Summary of Best Practices
Upvotes: 2
Reputation: 262534
It is one way to do what in a relational database you would do with a JOIN (something that you cannot do in MongoDB).
For example, you could have a MongoDB document as a blog post, and embed the list of comments right in there.
Then you can (for example):
All that would be impossible (or at least difficult) if the comments were stored in their own collection as separate documents.
Upvotes: 4