December 11, 2026 · Advent of MongoDB
11. Grounded Solved
Easy$max$match after $group
"Fine," Dusty sighs. "One of the team hurt a hoof in practice. We've kept it quiet. Nobody wants a panic in December."
Your task
Find every reindeer whose last flight was before 2026-11-26. Return reindeer and lastFlight (the date of that flight), sorted by name.
Your answer returns 1 document with the fields reindeer, lastFlight. Order matters.
What happens next
Comet is resting in the warm stall with a very fluffy bandage. Seven reindeer instead of eight. You make a note: who else knew about this?
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 after the $group filters on the computed maximum.Solution
db.flights.aggregate([
{ $group: { _id: "$reindeerId", lastFlight: { $max: "$flownOn" } } },
{ $match: { lastFlight: { $lt: ISODate("2026-11-26") } } },
{ $lookup: { from: "reindeer", localField: "_id", foreignField: "_id", as: "r" } },
{ $project: { _id: 0, reindeer: { $first: "$r.name" }, lastFlight: 1 } },
{ $sort: { reindeer: 1 } }
])
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of SQL.