Courseiva
Aggregation Framework →mediumMultiple Choice

C100DEV Aggregation Framework Practice Question

You are building an aggregation pipeline on a collection of sensor readings where each document has a `timestamp` field and a `value` field. You need to compute, for each calendar day, the highest `value` and the average `value` across all readings for that day. Which `$group` stage accomplishes this?

⚠ Common exam trap

The trap here is assuming that grouping by the raw `timestamp` field automatically produces daily buckets, when in fact it creates one group per distinct timestamp.

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

✓

{ $group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$timestamp" } }, maxValue: { $max: "$value" }, avgValue: { $avg: "$value" } } }

The `$group` stage must group by a day-level key while applying the correct accumulators to the `value` field. Using `$dateToString` in `_id` collapses all readings for a calendar day into one document, and `$max` plus `$avg` return the highest and mean values. Grouping by raw timestamps or using `$sum` fails to satisfy the daily maximum and average requirement.

Answer analysis

Option-by-option breakdown

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

  • ✗

    { $group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$timestamp" } }, maxValue: { $max: "$value" }, avgValue: { $sum: "$value" } } }

    Why it's wrong here

    The grouping key is correct, but `$sum` adds values rather than averaging them. The scenario requires the average `value` per day, which is the `$avg` accumulator. Using `$sum` would return the total of all readings for the day, not the mean, so the result would not meet the stated requirement.

  • ✗

    { $group: { _id: "$timestamp", maxValue: { $max: "$value" }, avgValue: { $avg: "$value" } } }

    Why it's wrong here

    Grouping by the raw `timestamp` value creates one group per distinct timestamp, not per calendar day. Since sensor readings occur at many different times within a day, this would produce far too many groups and would not aggregate by day. `$dateToString` or a date truncation expression is needed to collapse readings into daily buckets.

  • ✗

    { $group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$timestamp" } }, maxValue: { $max: "$value" }, avgValue: { $avg: "$timestamp" } } }

    Why it's wrong here

    The `$avg` accumulator is applied to `timestamp` instead of `value`. Averaging timestamps produces a meaningless average time, not the average sensor reading. The scenario asks for the average `value`, so the accumulator must reference the `value` field to return the correct result.

  • ✓

    { $group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$timestamp" } }, maxValue: { $max: "$value" }, avgValue: { $avg: "$value" } } }

    Why this is correct

    This stage groups by the formatted date string derived from `timestamp` and applies the `$max` and `$avg` accumulators to `value`. `$max` returns the highest value per group and `$avg` returns the mean, both valid accumulators. The `_id` expression using `$dateToString` correctly produces one group per calendar day, which is exactly what the scenario requires.

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.