Skip to content
Learn Netverks

Lesson

Step 16/36 44% through track

schema-design-patterns

Schema design patterns

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

This lesson

This lesson teaches Schema design patterns: 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 Schema design patterns in contexts like: Content catalogs, event logs, mobile sync backends, and polyglot stacks beside SQL services.

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.

Model for how the app reads data: embed one-to-few, reference one-to-many, bucket high-cardinality time series.

Embed one-to-few

db.orders.insertOne({
  customerId: 'c-1',
  lines: [
    { sku: 'A1', qty: 1, price: 9.99 },
    { sku: 'B2', qty: 2, price: 12.0 }
  ]
})

Practice: Run on practice in mongosh.

Reference one-to-many

// orders hold customerId; customers in separate collection
db.customers.insertOne({ _id: 'c-1', name: 'Acme' })
db.orders.insertOne({ customerId: 'c-1', total: 50 })

Bucket pattern (concept)

Store time-series events in documents with arrays capped per hour/day to avoid unbounded document growth.

Important interview questions and answers

  1. Q: Embedding downside?
    A: Document growth and duplicate data when parent copies change.
  2. Q: Reference downside?
    A: Requires second query or $lookup—more round trips.

Self-check

  1. When embed line items?
  2. When reference customers instead?

Tip: Embed one-to-few; reference one-to-many unbounded children.

Interview prep

Embed when?
One-to-few, read together, bounded size.
Bucket pattern?
Groups time-series events to cap document growth.

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

  • Bucket pattern?
  • Embed lines?

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