C100DEV Aggregation Framework Practice Question
Exhibit
db.collection.aggregate([ { $project: { result: { $add: ["$price", "$tax"] } } } ])Refer to the exhibit. What is the expected behavior if the 'price' field exists but the 'tax' field is missing in a document?
⚠ Common exam trap
Test-takers frequently assume that missing fields in arithmetic expressions are treated as zero, expecting a valid calculation instead of a null result.
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 returns a null value for the 'result' field.
In MongoDB, arithmetic expressions like $add treat missing fields as null. When any input in an arithmetic expression is null, the result of the entire expression is null. Consequently, the 'result' field will be set to null for those documents. This behavior is intentional to alert developers to incomplete data and requires explicit handling, such as using $ifNull, to ensure valid calculations are produced when expected data might be missing.
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 treats the missing field as 0 and returns the price.
Why it's wrong here
The aggregation engine does not automatically assume 0 for missing fields in arithmetic operations. Instead, it evaluates the result as null. This is a crucial distinction to remember, as it often causes unexpected results when performing calculations on sparse datasets where some fields may not be populated.
- ✓
It returns a null value for the 'result' field.
Why this is correct
In MongoDB arithmetic operators, if any of the operand values are null or refer to a missing field, the entire result is null. This forces developers to be explicit about how to handle missing values by using operators like $ifNull to provide default values for calculations.
- ✗
The operation throws an error due to the missing field.
Why it's wrong here
Arithmetic operations are designed to handle missing fields gracefully by returning null, rather than failing the entire pipeline. While this result might not be what the developer wants, it is not considered an error state, allowing the pipeline to continue processing other documents normally.
- ✗
It ignores the price and returns a value of 0.
Why it's wrong here
The result is null, not 0. The expression evaluates as null because one of the inputs is missing. Ignoring the price would be incorrect logic, as the price is present, but the overall operation cannot be completed because the tax value is undefined, resulting in a null outcome.
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.