December 10, 2026 · Advent of MongoDB
10. Reindeer games Solved
Easy$match on dates$lookup
You need some air. Dusty Hayloft, who runs Reindeer Care, invites you to the stables to see the training log. Every practice flight is in flights, with its km.
Your task
Total the kilometres each reindeer flew in November 2026. Return reindeer (the name) and km, most first, then by name.
Your answer returns 8 documents with the fields reindeer, km. Order matters.
What happens next
Dasher shows off. Blitzen pretends not to care. But one name is lower than it should be, and Dusty won't quite meet your eye.
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
Solution
db.flights.aggregate([
{ $match: { flownOn: { $gte: ISODate("2026-11-01"), $lt: ISODate("2026-12-01") } } },
{ $group: { _id: "$reindeerId", km: { $sum: "$km" } } },
{ $lookup: { from: "reindeer", localField: "_id", foreignField: "_id", as: "r" } },
{ $project: { _id: 0, reindeer: { $first: "$r.name" }, km: 1 } },
{ $sort: { km: -1, reindeer: 1 } }
])
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of SQL.