All academies
Roadmap
LEVEL 12 · REAL PROJECTS

Schema Design Patterns

14 min read

Real MongoDB skill is data modeling. Unlike relational design (normalize everything), document design starts from your query patterns: model the data the way the application uses it.

Core patterns

1. Embedding — one-to-few relationships read together (order + line items).

2. Referencing — one-to-many where the 'many' is unbounded or shared (product ↔ reviews).

3. Extended reference — store a *copy of a few hot fields* alongside the reference to avoid $lookup on every read (order stores customerName next to customerId).

4. Bucketing — group time-series points into per-hour/per-day documents.

5. Computed — precompute aggregates (product stores avgRating, updated on each review).

Anti-patterns

Unbounded arrays that grow forever (a user document holding every event), massive documents near the 16 MB limit, and 'relational thinking' — one collection per entity with $lookup everywhere. If every query needs three $lookups, the model is wrong.

Where to go next

Head to the Projects section and build the e-commerce, banking, and social media schemas — each includes schema design, queries, indexes, and aggregations you can run in the playground.

Check your understanding

Q1.

What should drive a MongoDB schema design?

Q2.

An order document stores customerId AND a copy of customerName. Which pattern is this?

Q3.

A single MongoDB document can be at most 16 MB.