C100DEV Aggregation Framework Practice Question
A developer is building an aggregation pipeline on a collection of sensor readings. The pipeline must group documents by sensorId and compute two values: the total number of readings and the timestamp of the most recent reading. Which $group accumulator pair should be used?
⚠ Common exam trap
The trap here is assuming $last returns the most recent timestamp, when it actually returns the last document processed in the group unless the pipeline is explicitly sorted beforehand.
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
✓
{ $sum: 1 } and { $max: "$timestamp" }
Counting documents in a group requires an accumulator that increments per document, and $sum with a literal 1 achieves this. To retrieve the most recent reading, $max on the timestamp field returns the highest timestamp value in each group. These two accumulators satisfy both requirements in a single $group stage without needing an extra sort.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
{ $sum: 1 } and { $max: "$timestamp" }
Why this is correct
Using $sum with a literal 1 counts one per document, yielding the total number of readings in each group. Applying $max to the timestamp field returns the largest (most recent) timestamp value per group, which is exactly the latest reading time. Both accumulators are valid within $group and produce the two required computed fields in a single pass.
- ✗
{ $count: 1 } and { $last: "$timestamp" }
Why it's wrong here
$count is an accumulator introduced in MongoDB 5.0, but using it as { $count: 1 } is not a valid expression syntax for counting within $group; the correct form is { $count: {} }. Even if valid, $last returns the timestamp of the last document encountered, which is not guaranteed to be the most recent unless the input is sorted first.
- ✗
{ $sum: "$timestamp" } and { $max: "$timestamp" }
Why it's wrong here
Applying $sum to the timestamp field would attempt to add numeric timestamp values, producing a meaningless sum rather than a count of readings. The $max portion is correct for the latest reading, but the counting requirement fails because $sum on a timestamp field does not count documents. A literal 1 is needed to count each document.
- ✗
{ $size: 1 } and { $max: "$timestamp" }
Why it's wrong here
$size is not an accumulator and cannot be used inside $group; it is an array expression operator that returns the number of elements in an array. Using it here would raise an error. Even conceptually, there is no way to count group members with $size. The $max portion is valid, but the pair as a whole is invalid.
About these practice questions
This C100DEV question is part of Courseiva's 259-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
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.