Courseiva
CRUD Operations →hardMultiple Choice

C100DEV CRUD Operations Practice Question

A developer must update a document in the 'accounts' collection by incrementing the 'balance' field by 25 and simultaneously setting the 'lastUpdated' field to the current date. The update must apply only if the account is active. Which update statement satisfies all conditions?

⚠ Common exam trap

The trap here is forgetting that a document without update operators is treated as a full replacement, silently dropping other fields instead of incrementing.

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

✓

updateOne({ active: true }, { $inc: { balance: 25 }, $set: { lastUpdated: new Date() } })

The correct approach is updateOne with a filter on active, $inc for the numeric change, and $set for the timestamp. Using update operators applies atomic field-level changes to one matched document. Omitting operators triggers replacement semantics, updateMany affects too many documents, and replaceOne forbids modifier keys, so each alternative violates part of the requirement.

Answer analysis

Option-by-option breakdown

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

  • ✗

    replaceOne({ active: true }, { $inc: { balance: 25 }, $set: { lastUpdated: new Date() } })

    Why it's wrong here

    replaceOne expects a full replacement document as its second argument and rejects update operators like $inc and $set. Passing them raises an error because replacement documents cannot contain modifier keys. Even if it succeeded, it would overwrite the document rather than increment the field.

  • ✓

    updateOne({ active: true }, { $inc: { balance: 25 }, $set: { lastUpdated: new Date() } })

    Why this is correct

    This updateOne call filters for active accounts, uses $inc to add 25 to balance, and $set to write the current date. Both update operators are applied atomically to the matched document, satisfying all three requirements in a single round trip. It is the idiomatic way to combine multiple field modifications with a conditional filter.

  • ✗

    updateMany({ active: true }, { $inc: { balance: 25 }, $set: { lastUpdated: new Date() } })

    Why it's wrong here

    updateMany would modify every active account, not a single document. The scenario implies updating one account's balance by 25, so applying the change to all active accounts would corrupt balances across the collection. updateOne is appropriate when a single document should be affected.

  • ✗

    updateOne({ active: true }, { balance: 25, lastUpdated: new Date() })

    Why it's wrong here

    Without update operators, the second argument is treated as a replacement document, so the entire account would be replaced by { balance: 25, lastUpdated: ... }, discarding other fields and not incrementing balance. This is a classic replacement-versus-modifier mistake. It fails the requirement to increment the existing balance.

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 →

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 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.