Skip to content
Learn Netverks

Lesson

Step 17/36 47% through track

embedded-vs-referenced

Embedded vs referenced data

Last reviewed Jun 1, 2026 Content v20260601
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Embedded vs referenced data: document modeling, query operators, and aggregation patterns for MongoDB.

Embed vs reference is the core Mongo design decision—wrong choice causes 16 MB limits or N+1 queries.

You will apply Embedded vs referenced data in contexts like: Order histories with customer names, CMS pages with blocks, and catalogs with variable attributes.

Copy JavaScript shell queries from each lesson into mongosh or MongoDB Atlas Data Explorer—inspect matched documents and explain plans. The in-browser lab (execution_profile: none) ships later; mongosh is the practice path now.

When you can explain the previous lesson's ideas without copying example queries verbatim.

Choose embed when data is read together and bounded; reference when shared entities update often or fan-out is huge.

Decision checklist

  • Read together in UI? → lean embed
  • Unbounded children (comments)? → reference or bucket
  • Many writers to same subdoc? → reference
  • Need SQL-style reports? → consider SQL or $lookup pipelines

Duplication trade-off

Embedding duplicates customer name on every order for fast reads—accept staleness or sync on change.

Anti-pattern: unbounded arrays

// Avoid: comments[] growing forever on one post document
// Prefer: db.comments with postId index

Practice: Run on practice in mongosh.

Important interview questions and answers

  1. Q: Atomic update of embed?
    A: Single-document updates are atomic—multi-doc needs transactions.
  2. Q: $lookup cost?
    A: Joins at query time—index foreign keys like customerId.

Self-check

  1. Example of unbounded array risk.
  2. What makes single-doc updates atomic?

Pitfall: Unbounded arrays inside one document—move to child collection.

Interview prep

Reference when?
Shared entities, unbounded children, frequent updates to child set.
Atomicity?
Single-document updates atomic; multi-doc needs transactions.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Unbounded array?
  • Atomic single doc?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump