C100DEV CRUD Operations Practice Question
An application needs to update a user document in the 'users' collection. If the document does not exist, a new document must be inserted using fields from both the filter and the update document. Which parameter accomplishes this behavior in MongoDB?
⚠ Common exam trap
Candidates often forget that an upsert merges the query filter and the update document, sometimes incorrectly assuming it only inserts the update document when a match is not found.
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
✓
Setting the { upsert: true } option in updateOne or findOneAndUpdate.
The upsert option instructs MongoDB to insert a new document if no existing document matches the query filter. When combined with update operators, the final document is constructed by merging the query filter with the update operators, which is crucial for idempotent bootstrapping patterns.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Setting the { writeConcern: { w: 'majority' } } option during the update operation.
Why it's wrong here
Write concern defines the acknowledgment level required from the replica set before returning success. It dictates durability guarantees rather than controlling whether missing documents are inserted or how document fields are constructed during update operations.
- ✗
Setting the { returnDocument: 'after' } option in the findOneAndUpdate method.
Why it's wrong here
returnDocument controls whether the returned document reflects pre- or post-update state; it does not create a document when none matches. It is tempting because it is commonly paired with upsert-style updates, and would be correct when you need the modified document returned after a successful findOneAndUpdate.
- ✓
Setting the { upsert: true } option in updateOne or findOneAndUpdate.
Why this is correct
Upsert combines update and insert semantics in one atomic operation: when no document matches the filter, MongoDB inserts a new document built from the filter equality fields plus the update operators. This exactly meets the requirement to insert using fields from both documents.
- ✗
Setting the { multi: true } option to force updates across multiple matching records.
Why it's wrong here
The multi option controls how many matching documents an update affects, not insert-on-miss behaviour. It is tempting because it is the standard parameter for bulk updates, and would be correct when a single update must modify every document matching the filter rather than just the first.
About these practice questions
Courseiva writes every C100DEV question from scratch — 259 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 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.