Courseiva
CRUD Operations →mediumMultiple Choice

C100DEV CRUD Operations Practice Question

A logistics application stores shipment events in the 'shipments' collection. Each document contains a field 'events' that is an array of subdocuments with fields 'status' and 'timestamp'. You need to remove the subdocument where 'status' equals 'cancelled' from all documents in the collection, without affecting other array elements. Which update operation should you use?

⚠ Common exam trap

Many exam-takers confuse $pull with $pullAll, assuming that $pullAll can remove subdocuments by a single field match, but it requires exact element matches.

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.updateMany({}, { $pull: { events: { status: 'cancelled' } } })

The $pull operator is designed to remove array elements that match a specified condition, making it ideal for removing subdocuments based on a field value. It works with updateMany to affect all documents. Other operators like $unset, $pop, and $pullAll do not support conditional removal of subdocuments based on a field, so they would not achieve the desired result.

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.updateMany({}, { $pull: { events: { status: 'cancelled' } } })

    Why this is correct

    The $pull operator removes all array elements that match a specified condition. Here, it removes subdocuments where status equals 'cancelled' from the 'events' array in every document. It does not affect other array elements, and updateMany applies the change to all matching documents. This is the correct tool for removing specific array elements based on a field value.

  • ✗

    db.shipments.updateMany({}, { $pullAll: { events: [{ status: 'cancelled' }] } })

    Why it's wrong here

    $pullAll removes all instances of the specified values from an array. It requires exact matches of entire elements, not partial matches on subdocument fields. Since the subdocuments also contain a 'timestamp' field, an exact match with only 'status' would not match any elements. Thus, it would not remove the intended subdocuments.

  • ✗

    db.shipments.updateMany({}, { $unset: { events: { status: 'cancelled' } } })

    Why it's wrong here

    $unset removes a field entirely, not an array element. Using it with a query on an array element is not valid syntax for removing a subdocument from an array. It would either fail or remove the entire 'events' field if used with a positional operator, which is not the intended behavior. It does not selectively remove matching array elements.

  • ✗

    db.shipments.updateMany({}, { $pop: { events: { status: 'cancelled' } } })

    Why it's wrong here

    $pop removes the first or last element of an array, not elements matching a condition. It takes a value of 1 or -1 to indicate which end to remove. It cannot filter by subdocument fields. Using it here would remove an arbitrary element from the array, not necessarily the one with status 'cancelled', leading to data corruption.

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.