C100DEV Aggregation Framework Practice Question
A retail company stores orders in a collection where each document has a `customerId` field and a `total` field. The analytics team needs to see, for each customer, both the sum of all order totals and a list of the individual order totals. Which aggregation pipeline stage and accumulator combination should be used?
⚠ Common exam trap
A common mix-up: candidates confuse $push and $addToSet in a $group stage, assuming both preserve all values when only $push includes duplicates.
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 with { _id: "$customerId", totalSum: { $sum: "$total" }, totals: { $push: "$total" } }
The $group stage groups documents by customerId, and within it, $sum calculates the total of all total fields while $push collects each total into an array. This yields one document per customer containing both the sum and the list of individual totals, meeting the analytics requirement without extra stages that would alter the output shape.
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 with { _id: "$customerId", totalSum: { $sum: "$total" }, totals: { $push: "$total" } }
Why this is correct
This $group stage groups documents by customerId and uses $sum to compute the total of all total values, while $push collects each total value into an array. Both accumulators operate on the same field but produce different results, exactly matching the requirement for a sum and a list of individual totals.
- ✗
$project with { customerId: 1, totalSum: { $sum: "$total" }, totals: { $push: "$total" } }
Why it's wrong here
$project cannot use $sum or $push as accumulators; these are accumulator operators only valid within a $group stage. Using them in $project would result in an error or unexpected behavior. The $project stage is for reshaping documents, not for grouping and aggregating across multiple documents.
- ✗
$group with { _id: "$customerId", totalSum: { $sum: "$total" }, totals: { $addToSet: "$total" } }
Why it's wrong here
$addToSet creates an array of unique values, so duplicate order totals for the same customer would be removed. The requirement is to list all individual order totals, not just distinct ones. While $sum correctly calculates the total, the $addToSet accumulator fails to preserve duplicates, making this option incorrect.
- ✗
$group with { _id: "$customerId", totalSum: { $sum: "$total" }, totals: { $push: "$total" } } followed by $unwind on totals
Why it's wrong here
The $group stage correctly computes the sum and array of totals, but adding a subsequent $unwind on totals would deconstruct the array into separate documents, losing the aggregated per-customer view. The requirement is to output one document per customer with both the sum and the list, so $unwind is unnecessary and counterproductive.
About these practice questions
One of 259 original C100DEV practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.