Question 25 / 50
Must KnowHardDesignData Modeling
How do you decide between embedding and referencing in MongoDB?
Think about it first.
Short answer
Embed when the data is read together, owned by the parent, and bounded in size. Reference when it is large, shared between parents, independently queried, or can grow without limit.
Why?
Embedding gives you one read and one-document atomic updates, which is why it removes most transaction needs. Referencing avoids unbounded documents and shared mutable copies. Order line items are the classic embed. A user's orders are the classic reference. Start from 'how is it read?', not from an ER diagram.
Interview tip
Answer with the access pattern first. Interviewers want to hear you ask how it is read.
Common mistake
Copying the SQL ER diagram one collection per table, then $lookup on every request — or the opposite, one mega-document.
How did you do?
Cheat Sheet