Courseiva
CRUD Operations →mediumMultiple Select

C100DBA CRUD Operations Practice Question

A DBA is reviewing update operations that use the upsert option. Which TWO statements about upsert behavior in MongoDB are correct? (Choose two.)

⚠ Common exam trap

The trap here is assuming that every field in the filter, including range conditions, is copied into the upserted document, when only equality conditions are used.

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

✓

If no document matches the filter, upsert inserts a new document based on the filter and the update operators.

Upsert inserts a new document when the filter matches nothing, building it from equality conditions in the filter plus the update operators. Non-equality operators do not contribute fields, so the inserted document may lack the filtered field. A unique index is recommended to prevent duplicate inserts from concurrent upserts, but it is not mandatory. Array operators such as $push are allowed in upserts.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    If no document matches the filter, upsert inserts a new document based on the filter and the update operators.

    Why this is correct

    When no document matches, the server constructs a new document from the equality conditions in the filter and the fields specified by update operators such as $set. This is the core behavior of upsert and is why it is useful for idempotent writes. The inserted document reflects both the filter's equality fields and the update's modifications.

  • ✗

    Upsert cannot be used with update operators that modify array elements, such as $push.

    Why it's wrong here

    Upsert works with array update operators. For example, an upsert with $push on a non-matching filter inserts a new document containing the array with the pushed element. There is no general prohibition against array operators in upserts. This statement is incorrect and would unnecessarily limit the use of upsert in application code.

  • ✗

    If multiple documents match the filter, upsert updates all of them and inserts no new document.

    Why it's wrong here

    With updateOne and upsert, if multiple documents match, only one is updated and no insert occurs. With updateMany and upsert, all matching documents are updated and still no insert occurs. The statement is misleading because it implies a general rule, but the key point is that upsert only inserts when there are zero matches, not that it updates all matches.

  • ✗

    Upsert always requires a unique index on the filter fields to avoid duplicate inserts.

    Why it's wrong here

    A unique index is not required for upsert to function. However, without a unique index, concurrent upserts can both fail to match and both insert, producing duplicates. The unique index prevents that race condition but is not a prerequisite for the operation itself. The statement overstates the requirement.

  • ✓

    If the filter contains only non-equality operators, the inserted document may not contain those fields.

    Why this is correct

    The inserted document is built from equality conditions in the filter. Operators such as $gt, $in, or $regex do not contribute fields to the new document. The update operators then add or modify fields. This is why an upsert with only range conditions can produce a document lacking the filtered field, which surprises many developers.

About these practice questions

One of 222 original C100DBA 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 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.