C100DEV CRUD Operations Practice Question
A logistics application stores shipment documents in the 'shipments' collection. Each document has a 'packages' array of embedded subdocuments, each with a 'trackingCode' field. A developer needs to remove only the embedded subdocument whose 'trackingCode' equals 'TRK-9981' from the document with '_id' 42, leaving all other packages untouched. Which update operation should be used?
⚠ Common exam trap
The trap here is assuming that $unset deletes an array element, when it actually replaces the matched element with null and leaves the array length unchanged.
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.shipments.updateOne({ _id: 42 }, { $pull: { packages: { trackingCode: "TRK-9981" } } })
The $pull operator deletes array elements that match a specified condition or value, which is exactly what removing a single embedded subdocument by its trackingCode requires. $pop and $pullAll operate positionally or on exact element values and cannot target a nested field match, while $unset would leave a null placeholder instead of deleting the element.
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.shipments.updateOne({ _id: 42 }, { $pull: { packages: { trackingCode: "TRK-9981" } } })
Why this is correct
The $pull operator removes every array element that matches the supplied condition, so this deletes only the embedded package whose trackingCode equals TRK-9981 while preserving the rest of the array and the parent document. The filter on _id restricts the update to the intended shipment, making this the precise and minimal operation for the scenario.
- ✗
db.shipments.updateOne({ _id: 42 }, { $pullAll: { packages: ["TRK-9981"] } })
Why it's wrong here
$pullAll removes all instances of the exact values listed from an array. Here the array holds embedded documents, not bare strings, so specifying the string "TRK-9981" matches nothing and the update changes no data. It cannot match on a field inside the subdocument, so it does not satisfy the scenario.
- ✗
db.shipments.updateOne({ _id: 42, "packages.trackingCode": "TRK-9981" }, { $unset: { "packages.$": "" } })
Why it's wrong here
$unset with the positional operator sets the matched array element to null rather than deleting it, leaving a null placeholder inside the array. The document would still contain a packages entry, which violates the requirement to remove the subdocument entirely. It also depends on the positional operator matching the array element via the query predicate.
- ✗
db.shipments.updateOne({ _id: 42 }, { $pop: { packages: 1 } })
Why it's wrong here
$pop removes either the first or last element of an array by position, not by matching a field value. With a value of 1 it deletes the final element of the packages array, which could be any package, not necessarily the one with trackingCode TRK-9981. It cannot express a value-based removal, so it fails the requirement.
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 →
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.