Courseiva
Aggregation Framework →mediumMultiple Choice

C100DEV Aggregation Framework Practice Question

Which aggregation stage allows you to replace the root of the document with a specified document or field?

⚠ Common exam trap

Candidates often mix up $replaceRoot with $project or $addFields, thinking those stages can completely swap the document root structure.

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

✓

$replaceRoot

The $replaceRoot stage is used to restructure a document by promoting a nested field to the top level. This is extremely useful for flattening complex, deeply nested JSON structures retrieved from other collections or generated through aggregations. By simplifying the document schema, it makes subsequent pipeline stages cleaner and easier to manage, which is a best practice for maintaining readable and maintainable aggregation pipelines in complex applications.

Answer analysis

Option-by-option breakdown

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

  • ✗

    $project

    Why it's wrong here

    $project is for including or excluding specific fields, not for replacing the document root. While $project can reshape a document, $replaceRoot is specifically designed for structural promotion, making it the more precise and intended operator for this type of document restructuring task.

  • ✓

    $replaceRoot

    Why this is correct

    $replaceRoot effectively promotes a nested document to the top level of the aggregation stream. This is the correct choice for restructuring documents by removing the original parent structure and placing a target inner document at the top level for further processing and analysis.

  • ✗

    $set

    Why it's wrong here

    $set is a shorthand for $addFields, used to add or update fields in a document. It does not possess the capability to discard the entire structure and replace the document root, making it inappropriate for restructuring the top-level schema of the result documents.

  • ✗

    $unwind

    Why it's wrong here

    $unwind is for splitting arrays into individual documents. It has no functional overlap with replacing the root of a document. Using $unwind for root replacement would result in unexpected multiplication of documents rather than the desired structural change to the individual document's root field.

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 →

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.