1 · MongoDB · DOCUMENT · 1 OF 2
Embedding: to embed inside
{ _id: "sword_dawn", name: "Клинок зари",
base_price: 100,
stats: { damage: 45, crit_chance: 0.15 },
effects: [
{ code: "burn", damage_per_sec: 5 },
{ code: "vampire", percent: 10 }
] }
A single read can return the entire object.
A nested $lookup isn't needed; the projection retrieves only the necessary fields.
A single record is atomic.
Multiple nested fields in a single document are either all updated or none at all—without a transaction.
INSERT IF
INSERT IF
INSERT IF
Read together
This relationship "consists of"
Quantities are limited
If you never access the child object separately from the parent, that's where it belongs.
An item's own stats belong to the item. The total burn in effects may be a current copy.
A numerical limit (maxItems: 5) has been specified, along with the mechanism for enforcing it on all write paths.
An attachment isn't necessarily a copy. Here, the stats are owned; there is no shared original. In P2, it has a different meaning: `effects.burn` repeats a shared fact and requires synchronization.