C100DEV Aggregation Framework Practice Question
A social media platform stores posts in a collection named posts. Each post document contains an array field `comments`, where each comment is a subdocument with fields `user` and `text`. The development team needs to generate a report that lists each comment as a separate document, including the post's `_id` and the comment's `user` and `text`. Which aggregation stage should be used to achieve this?
⚠ Common exam trap
Many candidates confuse $project with $unwind; $project can include the array but does not create separate documents for each element.
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
✓
$unwind
The $unwind stage is specifically designed to deconstruct an array field, outputting one document per array element. In this case, unwinding the `comments` array will produce a document for each comment, retaining the parent post's `_id`. This is the correct stage to flatten the comments array and meet the reporting 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.
- ✓
$unwind
Why this is correct
The $unwind stage deconstructs an array field from the input documents to output a document for each element. In this scenario, using $unwind on the `comments` array will produce one document per comment, preserving the parent post's fields such as `_id`. This exactly matches the requirement to list each comment as a separate document. Additional stages like $project can then reshape the output to include only the desired fields.
- ✗
$project
Why it's wrong here
$project is used to reshape documents by including, excluding, or computing fields. It can include the `comments` array as a whole, but it does not create separate documents for each array element. To achieve one document per comment, you need a stage that expands arrays. $project alone cannot accomplish that; it would leave the array intact.
- ✗
$replaceRoot
Why it's wrong here
$replaceRoot is used to replace the input document with a specified embedded document. It does not iterate over arrays. While it could promote a subdocument to the top level, it would only work if there is a single embedded document, not an array of comments. To expand an array, $unwind is required before or after $replaceRoot. Thus, $replaceRoot alone does not satisfy the requirement.
- ✗
$group
Why it's wrong here
$group is used to aggregate documents by a specified key and perform accumulations, such as sum or average. It does not expand arrays into multiple documents. In this scenario, using $group would combine documents, not separate comments. Therefore, it cannot produce one document per comment. The requirement is to flatten an array, which $group does not do.
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.