December 24, 2026 · Advent of MongoDB
24. Santa's message Solved
Hard$push$reduce$substrCP
Christmas Eve. The sleigh is packed for two trips, the reindeer are stamping, and Santa himself comes down to the data room for the first time. "The thirty children who were wronged," he says. "Each gets an apology note. Their top wishes are hiding a message for you."
Your task
Take the fake entries (night entries on LOGI-07) in the order they were made. For each one, take the first letter of that child's top wish (rank 1, the first toy on their list), and join the letters into one string. Return one row with message.
Your answer returns 1 document with the fields message.
What happens next
You read it out loud, and the whole workshop cheers. Santa shakes your hand. "Best data elf we've ever had. Well, the only one. But still the best." Bring that message to the finale to claim your prize.
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
loggedAt, look up the child and their first wishlist toy ($first: "$c.wishlist"), then $group with $push of { $substrCP: [name, 0, 1] } and join with $reduce and $concat.Solution
db.niceListLog.aggregate([
{ $match: { terminal: "LOGI-07", $expr: { $lt: [{ $hour: "$loggedAt" }, 5] } } },
{ $lookup: { from: "children", localField: "childId", foreignField: "_id", as: "c" } },
{ $project: { loggedAt: 1, top: { $first: { $first: "$c.wishlist" } } } },
{ $lookup: { from: "toys", localField: "top", foreignField: "_id", as: "toy" } },
{ $project: { loggedAt: 1, letter: { $substrCP: [{ $first: "$toy.name" }, 0, 1] } } },
{ $sort: { loggedAt: 1 } },
{ $group: { _id: null, letters: { $push: "$letter" } } },
{ $project: { _id: 0, message: { $reduce: { input: "$letters", initialValue: "", in: { $concat: ["$$value", "$$this"] } } } } }
])
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of SQL.