December 19, 2026 · Advent of MongoDB
19. A heavy sleigh Solved
Hard$lookup on an arrayone row per version
Grizzle loads the sleigh. Every nice child gets every toy on their wish list, so the list decides how heavy the sleigh is. Toys have a weightG in grams.
Your task
Compute the sleigh load in kg for two versions of the list: 'recorded' (every entry counts) and 'true' (ignoring the fake entries: night entries on LOGI-07). Return version and loadKg, sorted by version.
Your answer returns 2 documents with the fields version, loadKg. Order matters.
What happens next
Thirty children's worth of toys is a lot of weight. You remember Comet's bandage, and something clicks.
Solve today's puzzle to read what happens next.
The data
The North Pole's collections, a snapshot taken on December 1, 2026. Times are North Pole time (UTC). A MongoDB-compatible database runs in your browser: use Explore data to browse it.
elves_id, name, department, hiredOn, managerId (→ elves._id, null for the Head Elf), leave: [{ from, to }]children_id, name, country, city, utcOffset, age, wishlist: [toy _id, …] (top wish first)toys_id, name, category, buildMinutes, weightGniceListLog_id, childId, loggedAt, points, reason, recordedBy (→ elves._id), terminal (→ terminals._id)terminals_id (e.g. "LOGI-07"), location, departmentreindeer_id, name, maxLoadKgflights_id, reindeerId, flownOn, km, carrotsbuilds_id, toyId, elfId, builtAt, minutes, passedQccookieBatches_id, bakedAt, elfId, cookiesdoorSwipes_id, elfId, swipedAt, door, direction ("in" or "out")
Hints
Common traps
- Joining scores to wishes before summing points counts each entry once per wish.
Solution
db.niceListLog.aggregate([
{ $group: {
_id: "$childId",
recorded: { $sum: "$points" },
trueScore: { $sum: { $cond: [{ $and: [{ $eq: ["$terminal", "LOGI-07"] }, { $lt: [{ $hour: "$loggedAt" }, 5] }] }, 0, "$points"] } }
} },
{ $lookup: { from: "children", localField: "_id", foreignField: "_id", as: "c" } },
{ $unwind: "$c" },
{ $lookup: { from: "toys", localField: "c.wishlist", foreignField: "_id", as: "gifts" } },
{ $project: { recorded: 1, trueScore: 1, grams: { $sum: "$gifts.weightG" } } },
{ $group: {
_id: null,
recorded: { $sum: { $cond: [{ $gte: ["$recorded", 0] }, "$grams", 0] } },
true: { $sum: { $cond: [{ $gte: ["$trueScore", 0] }, "$grams", 0] } }
} },
{ $project: { _id: 0, rows: [
{ version: "recorded", loadKg: { $divide: ["$recorded", 1000] } },
{ version: "true", loadKg: { $divide: ["$true", 1000] } }
] } },
{ $unwind: "$rows" },
{ $replaceRoot: { newRoot: "$rows" } },
{ $sort: { version: 1 } }
])
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of SQL.