Skip to content
Ameen Abozaid
Planned lessonMID-042-L02

Embedding vs referencing

  • Lesson 2 of 7
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

decide where related data lives, based on access patterns.

Planned topics

  • Embed when data is read together, is owned by the parent, and stays bounded (an address inside an order).
  • Reference when data is shared, large, changes on its own, or grows without limit (all reviews of a product).
  • An unbounded array inside a document (reviews inside a product) is the classic mistake: documents grow, updates slow down, 16 MB limit.
  • Copy small, stable fields (customer display name) into the document to avoid lookups; accept update cost.
  • Do not copy a relational schema table by table.
Draft outline details

Demonstration

two options for reviews: embedded array in product (bad: unbounded) versus a reviews collection with productId (good), plus an embedded ratingSummary in product (small and bounded).

Check your understanding

Why not embed all reviews in the product document?

Show answer

The array is unbounded: the document grows and every update is costly.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.