Keep related data together when it is read together#
{
"userId": "42",
"name": "Maya",
"addresses": [{ "city": "Austin", "type": "home" }]
}A document can hold nested objects and arrays that form a bounded aggregate. This maps naturally to application objects and can retrieve related data in one operation.
Flexible does not mean schema-free#
The application still relies on field meaning, types, versions, indexes, and validation. Some document databases can enforce validation rules. Embedding avoids a join but can duplicate data, grow without bound, and make one shared value expensive to update across many documents.
| Embed | Reference |
|---|---|
| Data is bounded and read/updated together | Entity is shared, large, or changes independently |
| One-operation retrieval | Avoids widespread duplication |
| Watch document growth and repeated copies | Requires additional reads or application composition |
Related practice problems
Use the manifest-backed prompts below to apply this lesson in a complete design.
- MongoDB schema validationMongoDB Documentation
- Embedded dataMongoDB Documentation