Courseiva
CRUD Operations →mediumMultiple Choice

C100DEV CRUD Operations Practice Question

An inventory collection stores documents with a numeric 'quantity' field. A warehouse system must decrement quantity by 5 on a specific item, and if the field is missing it should be created starting from the decremented value. Which update operator and command achieve this?

⚠ Common exam trap

It's easy for candidates to confuse relative updates like $inc with absolute assignments like $set, which overwrite rather than adjust.

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.inventory.updateOne({ sku: "A1" }, { $inc: { quantity: -5 } })

$inc performs atomic relative addition, so a negative value decrements the field and creates it when absent. $set replaces the value outright, $mul scales instead of subtracting, and $push targets arrays rather than numeric fields, so none of those meet the decrement 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.

  • ✗

    db.inventory.updateOne({ sku: "A1" }, { $push: { quantity: -5 } })

    Why it's wrong here

    $push appends a value to an array field. Applying it to a numeric quantity would either error because the field is not an array or convert the field's type unexpectedly. It cannot decrement a number, so it fails the requirement entirely and risks corrupting the document's schema.

  • ✗

    db.inventory.updateOne({ sku: "A1" }, { $mul: { quantity: -5 } })

    Why it's wrong here

    $mul multiplies the field by the given value, so -5 would multiply quantity by negative five, producing a wildly incorrect result and potentially a negative stock figure. It performs scaling, not subtraction. This operator is meant for proportional changes such as applying a percentage factor, not for fixed decrements.

  • ✓

    db.inventory.updateOne({ sku: "A1" }, { $inc: { quantity: -5 } })

    Why this is correct

    $inc adds the given value to the field, so -5 decrements quantity by five. If the field does not exist, $inc creates it and sets it to the specified negative value, satisfying the requirement. updateOne() targets the single matching item, which is correct for adjusting one SKU's stock.

  • ✗

    db.inventory.updateOne({ sku: "A1" }, { $set: { quantity: -5 } })

    Why it's wrong here

    $set assigns an absolute value, so this would overwrite quantity with -5 regardless of its current amount rather than subtracting five. It also does not compute a relative change, which is the core requirement. This is a common mistake when the intent is arithmetic adjustment rather than replacement.

About these practice questions

One of 259 original C100DEV 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 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.