December 17, 2026 · Advent of MongoDB
17. Every single time Solved
Hardtwo statements$setIsSubset
A suspect has to have been there on every night the list was tampered with. Not most nights. Every one.
Your task
The edit nights are the dates with a night entry (00:00 to 04:59) on terminal LOGI-07. Return the elves who swiped in to the Logistics Bay between 00:00 and 04:59 on every edit night: just elf, sorted by name.
Your answer returns 2 documents with the fields elf. Order matters.
What happens next
Two names: Flurry the night guard, and Grizzle Pinecone, sleigh loading supervisor in Logistics. Flurry looks horrified. "I just walk through! Every hour, door to door. Check the times!" So you will.
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
const nights = db.niceListLog.aggregate([...]).toArray().map(d => d._id). Then keep elves whose set of nights contains all of them: $setIsSubset: [nights, "$nights"].Common traps
- Counting swipes instead of distinct nights lets someone who came in twice on one night look like they were there two nights.
Solution
const nights = db.niceListLog.aggregate([
{ $match: { terminal: "LOGI-07", $expr: { $lt: [{ $hour: "$loggedAt" }, 5] } } },
{ $group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$loggedAt" } } } }
]).toArray().map((d) => d._id);
db.doorSwipes.aggregate([
{ $match: { door: "Logistics Bay", direction: "in", $expr: { $lt: [{ $hour: "$swipedAt" }, 5] } } },
{ $group: { _id: "$elfId", nights: { $addToSet: { $dateToString: { format: "%Y-%m-%d", date: "$swipedAt" } } } } },
{ $match: { $expr: { $setIsSubset: [nights, "$nights"] } } },
{ $lookup: { from: "elves", localField: "_id", foreignField: "_id", as: "e" } },
{ $project: { _id: 0, elf: { $first: "$e.name" } } },
{ $sort: { elf: 1 } }
])
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of SQL.