APPENDIX · P2 · MONGODB · FOR SLIDES 7 AND 9
← Go to Slide 7
P2. Reference, Current Copy, and Snapshot
db.item_effects.findOne({ _id: "burn" })
db.item_configs.findOne({ _id: "sword_dawn" }, { effects: 1 })
db.purchase_history.findOne({ _id: "purchase-1" })
db.item_configs.aggregate([
{ $match: { effect_ids: { $exists: true } } },
{ $lookup: { from: "item_effects", localField: "effect_ids",
foreignField: "_id", as: "resolved" } },
{ $project: { effect_ids: 1, "resolved._id": 1,
"resolved.damage_per_sec": 1 } } ])
What the result should be
burn: damage_per_sec 6 // источник
sword_dawn.effects: burn 5 // текущая копия
purchase-1: price_paid 100,
effect_snapshot 5 // история
axe_dusk: resolved burn 6, freeze
staff_void: resolved [] // нет FK
The copy fell behind
The photo is accurate
Synchronization
Source 6, Sword 5 copy: A violation occurs if the allowable lag is exceeded.
5 in the purchase — a record of “how it was back then.” It cannot be updated along with the reference guide.
`updateMany` with `arrayFilters` set to `e.code = burn`—a transaction is required for an “all-or-nothing” set of copies.
Here, `effects.burn` is a copy; it does not contain the stats from slide 6. `purchase_history` in MongoDB merely illustrates a snapshot.