C100DBA CRUD Operations Practice Question
A retail application stores product documents in the `products` collection. Each document has an `inventory` array of embedded subdocuments, for example: `{ _id: 1, name: "Widget", inventory: [ { sku: "A1", qty: 5 }, { sku: "B2", qty: 8 } ] }`. The warehouse team needs to increase the `qty` of the subdocument with `sku: "B2"` by 3 for the product with `_id: 1`. Which update operation accomplishes this?
⚠ Common exam trap
The trap here is assuming that dot notation like `inventory.qty` automatically targets array element fields, when in fact it requires the positional operator to match a specific subdocument.
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.products.updateOne( { _id: 1, "inventory.sku": "B2" }, { $inc: { "inventory.$.qty": 3 } } )
The positional `$` operator updates the first array element that matches the query condition. Pairing `"inventory.sku": "B2"` in the filter with `"inventory.$.qty"` in the update ensures only the subdocument with that SKU is modified. Using `$inc` performs the required arithmetic and preserves the numeric field type, which is essential for inventory counts.
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.products.updateOne( { _id: 1, "inventory.sku": "B2" }, { $inc: { "inventory.0.qty": 3 } } )
Why it's wrong here
The path `inventory.0.qty` always targets the first element of the array, regardless of which subdocument matched the query. If "B2" is not at index 0, the wrong subdocument is updated. The positional operator is required to update the element that actually matched the query condition.
- ✗
db.products.updateOne( { _id: 1, "inventory.sku": "B2" }, { $set: { "inventory.$.qty": "3" } } )
Why it's wrong here
Using `$set` with the string "3" changes the field type from a number to a string, which breaks numeric operations and query comparisons. The requirement is to increase the existing numeric quantity by 3, so `$inc` with a numeric value is appropriate; `$set` with a string does not perform arithmetic.
- ✓
db.products.updateOne( { _id: 1, "inventory.sku": "B2" }, { $inc: { "inventory.$.qty": 3 } } )
Why this is correct
This correctly uses the positional `$` operator. The query identifies the array element whose `sku` equals "B2", and the positional operator updates the `qty` field of the matched array element only. This is the standard MongoDB pattern for updating a specific embedded subdocument in an array without replacing the whole array.
- ✗
db.products.updateOne( { _id: 1 }, { $inc: { "inventory.qty": 3 } } )
Why it's wrong here
Without the positional operator or an array filter, the path `inventory.qty` targets the `qty` field of the array itself, not of its elements. MongoDB will not match a scalar `qty` field on the array, so the `$inc` has no effect on the embedded subdocuments, leaving `qty` values unchanged.
About these practice questions
This C100DBA question is part of Courseiva's 222-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.