When should you embed documents vs reference them in MongoDB schema design?
The fundamental rule of MongoDB data modeling is: **data that is accessed together should be stored together**.
• Embed (Denormalize): When there is a 1-to-few relationship (e.g. user with 2-3 addresses), embedded data rarely changes independently, and child data has no lifecycle outside the parent. Delivers atomic single-read performance. • Reference (Normalize): When there is a 1-to-many or many-to-many relationship (e.g. authors to books, sensor logs), embedded sub-documents would grow unbounded past the 16MB document limit, or data is shared and queried across multiple entities.
// Good Embedding: 1-to-few, read together
{
"_id": 101,
"title": "Clean Code",
"publisher": { "name": "Prentice Hall", "country": "USA" },
"tags": ["programming", "architecture"]
}
// Good Referencing: 1-to-thousands, prevents document size explosion
{
"_id": 201,
"authorId": 101, // Reference to author document
"message": "Great book!",
"postedAt": ISODate("2026-02-10T12:00:00Z")
}Embedding addresses or publisher details avoids costly `$lookup` joins. Storing infinite comments as separate documents referencing `authorId` prevents exceeding the 16MB document boundary.
Ready for Replication & Replica Sets?
Take a quick test to evaluate yourself, or move straight to the next module.