Search⌘ K
AI Features

Embedded Documents vs. References: Trade-Offs and When to Choose

Understand the trade-offs between embedding and referencing related data in MongoDB. This lesson helps you decide when to embed related data within a document for faster reads and atomic updates, and when to reference it for independent growth and avoiding duplication. You will learn practical rules based on data access patterns, size constraints, and sharing requirements to model real-world relationships effectively in your MERN stack applications.

Many schema design decisions come down to one question about related data: embed it inside the document that uses it, or store it separately and reference it. MongoDB supports both, and the choice affects how the application reads, writes, scales, and stays maintainable. This lesson compares the two patterns: embedding and referencing and gives a practical rule for choosing based on access patterns.

Earlier chapters previewed this trade-off. In this lesson, it becomes the main subject. Understanding this trade-off helps with schema decisions throughout the rest of the course.

Note: This course references related documents by the string field id (for example, orders.userId holds "0001"). MongoDB’s default reference is an ObjectId pointing to another document’s _id; the trade-offs in this lesson apply the same way regardless of which identifier type a project uses.

To make the contrast concrete, the next visual should show the same data modeled both ways:

The same relationship is modeled as an embedded document and as a reference
The same relationship is modeled as an embedded document and as a reference

That comparison starts with the two patterns themselves:

The two patterns

...