Question 26 / 50
Would you embed order items inside an order or store them in a separate collection? What factors would you consider?
Short answer
Embed them in almost every commerce model: they are read with the order, not shared, and bounded. Split them only if a single order can have an unbounded number of lines, or if lines are queried heavily on their own without the parent.
Why?
A receipt is an aggregate. Quantity, name, and unitPrice belong together so a later catalogue price change does not rewrite history. Independent item documents make sense for warehouse pick-lists at huge line counts, not for a typical checkout order.
Interview tip
Mention the price snapshot in the same breath. Embedding without snapshotting live catalogue price is a business bug.
Common mistake
Referencing products only by id on the line with no name or price, then $lookup for every historical order.
How did you do?
Cheat Sheet