December 20, 2026 · Advent of MongoDB
20. Seven reindeer Solved
Medium$lookup$match on a joined array
Each reindeer can pull maxLoadKg. Only reindeer that are still flying can pull anything on Christmas Eve.
Your task
Add up the maxLoadKg of every reindeer that has flown on or after 2026-11-26. Return one row: capacityKg.
Your answer returns 1 document with the fields capacityKg.
What happens next
There it is. The recorded list fits under seven reindeer's capacity, barely. The true list doesn't. Grizzle found out about Comet, panicked, and quietly made thirty children "naughty" so the sleigh would still fly. Wrong, but not wicked. Grizzle confesses in tears over a cold cocoa. Now Christmas needs a real plan.
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
$match on "f.flownOn": a match on an array field matches if any element does.Solution
db.reindeer.aggregate([
{ $lookup: { from: "flights", localField: "_id", foreignField: "reindeerId", as: "f" } },
{ $match: { "f.flownOn": { $gte: ISODate("2026-11-26") } } },
{ $group: { _id: null, capacityKg: { $sum: "$maxLoadKg" } } },
{ $project: { _id: 0, capacityKg: 1 } }
])
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of SQL.