Courseiva
CRUD Operations →mediumMultiple Choice

C100DBA CRUD Operations Practice Question

Which method should you use to update multiple documents in a collection and insert a new document if no matches are found?

⚠ Common exam trap

Candidates often confuse updateMany with updateOne or forget that the upsert option must be explicitly set to true, otherwise no new document will be inserted if zero matches are found.

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.collection.updateMany({filter}, {update}, {upsert: true})

The updateMany method modifies all documents matching the filter. When combined with the 'upsert' option set to true, it ensures that if no documents match the query criteria, a single new document is created containing the filter and update criteria. This pattern is critical for idempotent data ingestion pipelines where you must guarantee existence of records without performing separate check-then-insert logic, thus preventing race conditions.

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.collection.updateOne()

    Why it's wrong here

    This method only modifies a single document. If multiple documents match the filter criteria, only the first one encountered is updated. While it supports the upsert option, it fails to meet the requirement of updating all matching documents in the collection simultaneously during a single execution.

  • ✗

    db.collection.replaceOne()

    Why it's wrong here

    This operation completely replaces the content of a single document. It does not perform a partial update on multiple documents. Using this would result in data loss for other matching documents and would not fulfill the requirement of updating all records that meet the specified filter criteria.

  • ✓

    db.collection.updateMany({filter}, {update}, {upsert: true})

    Why this is correct

    This is the correct command structure for updating multiple documents while enabling the upsert feature. By setting the third parameter object with upsert true, MongoDB will apply the update to all matching documents or create a new document based on the query and update data if no matches exist.

  • ✗

    db.collection.save()

    Why it's wrong here

    The save method is deprecated in modern MongoDB drivers and is not an atomic update operation. It behaves as an upsert for a single document based on the _id field. It lacks the capability to update multiple documents or perform complex field-level updates efficiently across a query set.

About these practice questions

Courseiva writes every C100DBA question from scratch — 222 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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 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.