The most important design decision in MongoDB is whether to embed related data inside a single document or reference it in another collection.
- Embed when data is read together, has a small bounded size (e.g., user address, order line items), and belongs strictly to the parent.
- Reference (store
ObjectId) when data grows unboundedly (e.g., thousands of comments), is shared across many parents, or is updated independently.
ADVERTISEMENT