December 23, 2026 · Advent of MongoDB
23. Setting it right Solved
Medium$cond$group
Tansy is ready to publish the corrected Nice List. Before she does, she wants the same count you gave her on day 5, done properly.
Your task
Count the children on each side of the true list, ignoring the fake entries (night entries on LOGI-07). Return status ('nice' or 'naughty') and children, sorted by status.
Your answer returns 2 documents with the fields status, children. Order matters.
What happens next
Six naughty children, just like last year. Tansy laughs so hard her hat falls off. Holly, Juniper and Sprig, back from the spa and very relaxed, are horrified to hear what happened to their badges, and Grizzle has offered to wrap every one of the thirty children's presents by hand.
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.niceListLog.aggregate([
{ $group: { _id: "$childId", score: { $sum: { $cond: [{ $and: [{ $eq: ["$terminal", "LOGI-07"] }, { $lt: [{ $hour: "$loggedAt" }, 5] }] }, 0, "$points"] } } } },
{ $group: { _id: { $cond: [{ $gte: ["$score", 0] }, "nice", "naughty"] }, children: { $sum: 1 } } },
{ $project: { _id: 0, status: "$_id", children: 1 } },
{ $sort: { status: 1 } }
])
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of SQL.