Courseiva
CRUD Operations →hardMultiple Choice

C100DEV CRUD Operations Practice Question

A document in the 'profiles' collection has an embedded array 'contacts' of subdocuments, each with 'type' and 'value' fields. A developer must change the 'value' of the subdocument whose 'type' is 'email' without altering any other array element. Which update is correct?

⚠ Common exam trap

The trap here is using the plain positional operator or a numeric index when the element must be selected by a field condition.

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.profiles.updateOne({ _id: 1 }, { $set: { "contacts.$[elem].value": "new@x.com" } }, { arrayFilters: [{ "elem.type": "email" }] })

The filtered positional operator with arrayFilters matches subdocuments by condition, so only the email element changes. A hardcoded index may hit the wrong entry, the plain positional operator needs an array condition in the query, and replacing the whole array deletes other contacts.

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.profiles.updateOne({ _id: 1 }, { $set: { "contacts.$[elem].value": "new@x.com" } }, { arrayFilters: [{ "elem.type": "email" }] })

    Why this is correct

    The positional filtered operator $[elem] combined with arrayFilters updates only array elements matching the filter, so just the email subdocument's value changes. This is the precise tool when an array contains mixed element types and only some should be modified. It avoids touching phone or other entries.

  • ✗

    db.profiles.updateOne({ _id: 1 }, { $set: { "contacts.$.value": "new@x.com" } })

    Why it's wrong here

    The positional $ operator refers to the first array element matched by the query filter, but the query here filters only on _id, so no array element was matched. Without a filter on the array, the positional operator cannot identify the email subdocument and the update fails or targets incorrectly. It requires a matching condition in the query itself.

  • ✗

    db.profiles.updateOne({ _id: 1 }, { $set: { contacts: [{ type: "email", value: "new@x.com" }] } })

    Why it's wrong here

    This replaces the entire contacts array with a single-element array, destroying all other contact entries. It is a wholesale overwrite rather than a targeted element update. While the email value would change, the collateral loss of other contacts makes it incorrect for the stated requirement of leaving other elements untouched.

  • ✗

    db.profiles.updateOne({ _id: 1 }, { $set: { "contacts.0.value": "new@x.com" } })

    Why it's wrong here

    Using the numeric index 0 targets whatever subdocument happens to be first, which may not be the email entry. Array order is not guaranteed to match semantic type, so this risks overwriting the wrong contact. It does not satisfy the requirement to update specifically the element whose type is email.

About these practice questions

This C100DEV question is part of Courseiva's 259-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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 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.