Courseiva
Aggregation Framework →mediumMultiple Choice

C100DEV Aggregation Framework Practice Question

You have a collection of sensor readings where each document includes a timestamp field `recordedAt` and a temperature field `tempC`. You need to generate a report that groups readings into 15-minute intervals and calculates the average temperature per interval. Which aggregation expression should you use to create the grouping key?

⚠ Common exam trap

The trap here is assuming that $dateToString or manual arithmetic can easily round to intervals, but they require extra steps and are error-prone.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

{ $dateTrunc: { date: "$recordedAt", unit: "minute", binSize: 15 } }

The $dateTrunc operator is designed to truncate dates to a specified unit and bin size, making it ideal for grouping into intervals. It handles all date components automatically, ensuring correct 15-minute buckets. The other options either do not round, are overly complex, or operate on partial components, leading to incorrect grouping.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    { $dateTrunc: { date: "$recordedAt", unit: "minute", binSize: 15 } }

    Why this is correct

    The $dateTrunc operator truncates a date to the specified unit and binSize, producing a date rounded down to the nearest 15-minute boundary. This creates a consistent grouping key for intervals like 10:00, 10:15, 10:30. It is the correct tool for time-bucketing in aggregation pipelines.

  • ✗

    { $dateFromParts: { year: { $year: "$recordedAt" }, month: { $month: "$recordedAt" }, day: { $dayOfMonth: "$recordedAt" }, hour: { $hour: "$recordedAt" }, minute: { $multiply: [ { $floor: { $divide: [ { $minute: "$recordedAt" }, 15 ] } }, 15 ] } } }

    Why it's wrong here

    This complex expression manually reconstructs a date with minutes rounded down to the nearest multiple of 15. While it could work, it is overly verbose and error-prone, especially with edge cases like hour rollover. The $dateTrunc operator is the intended, simpler solution.

  • ✗

    { $subtract: [ "$recordedAt", { $mod: [ { $minute: "$recordedAt" }, 15 ] } ] }

    Why it's wrong here

    This expression attempts to subtract the remainder of minutes modulo 15, but it operates on the minute component alone, not the full date. It would not correctly adjust the timestamp to the 15-minute boundary and would likely produce incorrect dates, especially across hour boundaries.

  • ✗

    { $dateToString: { format: "%Y-%m-%d %H:%M", date: "$recordedAt" } }

    Why it's wrong here

    While $dateToString can format dates, it does not round to 15-minute intervals. It would produce a string with the exact minute of each reading, resulting in many distinct groups rather than 15-minute buckets. You would need additional string manipulation to achieve the desired grouping.

About these practice questions

Courseiva writes every C100DEV question from scratch — 259 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official MongoDB exam blueprint

This C100DEV practice question is part of Courseiva's free MongoDB certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the C100DEV exam.