Courseiva
CRUD Operations →mediumMultiple Choice

C100DBA CRUD Operations Practice Question

You are a MongoDB DBA at a retail company. The 'orders' collection has a document with _id: 100 and status: 'pending'. You need to atomically update the status to 'shipped' only if the current status is 'pending'. Which update operation should you use?

⚠ Common exam trap

The trap here is assuming that any updateOne with a filter on _id is sufficient, but the filter must also include the condition on the field being changed to enforce conditional update.

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

✓

db.orders.updateOne({_id: 100, status: 'pending'}, {$set: {status: 'shipped'}})

The correct approach is to include the current status in the query filter so the update only applies when the status is 'pending'. This leverages MongoDB's atomic single-document updates, ensuring the condition and modification occur as one indivisible operation. Using a filter without the status condition would update regardless of the current value, risking data integrity.

Answer analysis

Option-by-option breakdown

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

  • ✗

    db.orders.replaceOne({_id: 100}, {status: 'shipped'})

    Why it's wrong here

    replaceOne replaces the entire document with the new document, removing all other fields except _id. This would delete any other fields in the order document, such as items or total, which is destructive and not intended. It also does not check the current status, so it could overwrite a different status.

  • ✓

    db.orders.updateOne({_id: 100, status: 'pending'}, {$set: {status: 'shipped'}})

    Why this is correct

    Including status: 'pending' in the query filter ensures the update only occurs if the document currently has that status. MongoDB's updateOne is atomic at the document level, so the check and update happen as a single operation, preventing race conditions where another process might change the status between a separate read and write.

  • ✗

    db.orders.updateOne({_id: 100}, {$set: {status: 'shipped'}})

    Why it's wrong here

    This updateOne without a status filter will set status to 'shipped' regardless of the current value. It does not enforce the condition that the existing status must be 'pending', so it could overwrite a different status such as 'cancelled' or 'delivered'. This does not meet the requirement of updating only if the current status is 'pending'.

  • ✗

    db.orders.findAndModify({query: {_id: 100}, update: {$set: {status: 'shipped'}}})

    Why it's wrong here

    findAndModify without a status condition in the query will update the document unconditionally. Although findAndModify is atomic, it does not enforce the requirement that the current status be 'pending'. It would also return the document before or after modification, but the core issue is the missing condition.

About these practice questions

One of 222 original C100DBA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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 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.