Choosing the Right Data Model
MongoDB Schema Design – Embed or Reference?
When should you embed documents vs reference them?
By Sharanmeet Singh••
Tags:MongoDBSchema DesignBest Practices
MongoDB Query Generator
Generate MongoDB queries and aggregation pipelines
MongoDB Schema Design
MongoDB offers two main ways to model relationships:
Embedding
{
"_id": 1,
"name": "Alice",
"orders": [ { "id": 1001, "amount": 200 } ]
}
- Good for small, related data
- Fast reads
Referencing
{
"_id": 1,
"name": "Alice",
"orderIds": [1001, 1002]
}
- Good for large collections
- More scalable
Rule of Thumb
- Embed if data is read together
- Reference if data grows large or is reused
Think in terms of access patterns, not just structure.