C100DBA CRUD Operations Practice Question
What happens if you run an update operation with the $set operator on a field that does not yet exist in the document?
⚠ Common exam trap
Many candidates falsely believe that running an update with $set on a missing field will throw an error or require prior schema definition.
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
✓
The field is created with the new value.
MongoDB is schema-flexible, meaning it will create the field if it is missing during an update operation. The $set operator is intelligent enough to add the field with the specified value, which simplifies code by eliminating the need for pre-checks or initialization logic. This is a core strength of the document model that allows for evolving data requirements without requiring explicit database migrations.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The update fails with an error.
Why it's wrong here
MongoDB does not require a predefined schema. When $set is used on a missing field, the database server adds the field to the document automatically. This behavior supports the document model's flexibility, allowing developers to add new data points to documents dynamically as application requirements change over time.
- ✓
The field is created with the new value.
Why this is correct
When $set targets a field that is currently absent from the document, MongoDB inserts that field and assigns it the provided value. This makes it trivial to perform incremental schema updates, enabling the application to store new data points immediately without requiring a full database rewrite.
- ✗
The update is ignored.
Why it's wrong here
The update is not ignored. If the query filter matches the document, the update will execute, and the new field will be added. MongoDB operations are designed to apply modifications reliably. Ignoring the update would lead to data inconsistency, which violates the principles of a predictable database system.
- ✗
The entire document is replaced.
Why it's wrong here
The $set operator is a field-level modifier, not a full document replacement. A full replacement would happen if you sent a raw document to the update method without an operator. Using $set specifically instructs MongoDB to modify only the specified fields, leaving the rest of the document intact.
About these practice questions
Courseiva writes every C100DBA question from scratch — 222 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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 C100DBA 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 C100DBA exam.