Courseiva
CRUD Operations →mediumMultiple Choice

C100DEV CRUD Operations Practice Question

A support ticketing system stores documents in the 'tickets' collection. An operator wants to add a new field 'priority' set to 'high' only for tickets whose 'status' is 'open' and that do not already have a 'priority' field. The update must not create any new documents and must not modify tickets that already have a 'priority' field. Which update operation should be used?

⚠ Common exam trap

The trap here is assuming that $setOnInsert updates existing documents or that upsert: true is needed to add a new field, when in fact $set with a precise filter is sufficient and safer.

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.tickets.updateMany({ status: 'open', priority: { $exists: false } }, { $set: { priority: 'high' } })

The correct operation must update multiple open tickets that lack a priority field, add the field without overwriting existing values, and avoid creating new documents. Using updateMany with a filter that includes $exists: false and a $set modifier satisfies all conditions. Operators like $setOnInsert or upsert options are designed for insert scenarios and would either do nothing or risk unintended inserts, while replaceOne would remove other fields.

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.tickets.updateMany({ status: 'open' }, { $set: { priority: 'high' } }, { upsert: true })

    Why it's wrong here

    This updates all open tickets regardless of whether priority already exists, overwriting any existing priority value. The upsert: true option also risks creating a new ticket document if no open ticket matches, which violates the requirement that no new documents be created. The filter is too broad and the upsert is inappropriate here.

  • ✗

    db.tickets.replaceOne({ status: 'open', priority: { $exists: false } }, { status: 'open', priority: 'high' })

    Why it's wrong here

    replaceOne replaces the entire matched document with the provided replacement document, which would discard all other fields such as ticket subject, description, and timestamps. It also only affects a single document, not all matching open tickets. This is destructive and does not meet the requirement to simply add a field to multiple documents.

  • ✓

    db.tickets.updateMany({ status: 'open', priority: { $exists: false } }, { $set: { priority: 'high' } })

    Why this is correct

    This operation uses updateMany with a filter that matches only open tickets lacking a priority field, and $set adds the field without inserting new documents. Because the filter includes $exists: false, tickets that already have priority are untouched, and updateMany never performs an upsert unless explicitly requested, so no new documents are created.

  • ✗

    db.tickets.updateMany({ status: 'open', priority: { $exists: false } }, { $setOnInsert: { priority: 'high' } })

    Why it's wrong here

    The $setOnInsert operator only applies when an upsert results in a new document being inserted. Since no upsert is specified, this update will match the correct tickets but apply no changes at all, leaving them without a priority field. The operator is intended for insert-time defaults, not for updating existing matched documents.

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.