C100DEV Aggregation Framework Practice Question
In an aggregation pipeline, what is the purpose of the $addFields stage?
⚠ Common exam trap
Candidates frequently confuse $addFields with $project, mistakenly believing that $addFields removes existing fields from the document, which is incorrect as $addFields explicitly preserves all original document fields.
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
✓
It adds new fields to documents, preserving existing fields.
The $addFields stage allows you to append new fields to documents by defining expressions. It is highly versatile, enabling computed fields, data restructuring, or field renaming without removing existing data. This is crucial for enriching data on the fly within the database, which avoids the overhead of modifying large collections on disk or performing complex logic within the application code.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It removes all existing fields and replaces them with new ones.
Why it's wrong here
Replacing all fields is the function of the $replaceRoot or $replaceWith stage, not $addFields. $addFields is designed to be non-destructive, preserving the original schema while extending it with new calculated values, which is essential for maintaining document integrity throughout a pipeline.
- ✓
It adds new fields to documents, preserving existing fields.
Why this is correct
$addFields adds specified fields to the input documents, and if a field already exists, it updates its value with the result of the expression. This is the standard mechanism for augmenting documents without losing pre-existing data, providing maximum flexibility for data reporting and transformation tasks.
- ✗
It filters the collection based on newly added fields.
Why it's wrong here
Filtering is performed by the $match stage. $addFields only performs calculations and field assignments; it does not have the ability to discard documents from the pipeline based on the values it computes. Combining $addFields with $match is necessary if filtering based on computed fields is required.
- ✗
It is a deprecated stage replaced by $project.
Why it's wrong here
$addFields is not deprecated; it is an active and essential stage in modern MongoDB aggregations. While $project can achieve similar results, $addFields is explicitly designed for adding fields while retaining all existing ones, making it more concise and readable for common document enrichment operations.
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.