Embedding keeps related data together for common reads and atomic document updates. References suit independent lifetimes, large relationships or data shared across many parents.
Before you start
You should understand documents, collections and indexes. Sketch representative documents and the reads and writes they must support. MongoDB-specific examples assume a collection with the shown fields; deployment topology, permissions and existing indexes can affect the operational behavior being discussed.
The practical goal is to reason through this situation: Embed a bounded shipping-address snapshot in an order; reference independently maintained products. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Identify shared lifetime
Related bounded data can belong within one document.
Step 2: Separate independent ownership
Reference entities updated independently or shared by many parents.
Step 3: Bound embedded growth
Avoid an array whose size grows without a practical limit.
Worked scenario
Embed a bounded shipping-address snapshot in an order; reference independently maintained products.
An order embeds the address used at purchase, preserving history when the customer moves. Product records remain referenced because their catalog lifecycle is independent. Embedding every customer’s full order history into one ever-growing document would create a different capacity and update problem.
Common mistake
Unbounded embedded arrays can grow beyond practical document limits.
Verify the behavior
Test common reads, independent updates and worst-case document growth.
Interview exercise
Model repeated customer details.
Answer and reasoning
Distinguish current shared data from historical snapshots, then choose ownership and update behavior deliberately.
Continue learning
Compare the scenario with the MongoDB interview questions and test your understanding with the MongoDB MCQs. For terminology and implementation details, consult the reference material.