Courseiva
CRUD Operations →mediumMultiple Choice

C100DBA CRUD Operations Practice Question

You are updating a document in the `products` collection. The document has an array field `tags`. You need to add the tag "sale" to the array only if it does not already exist, and you want to ensure that no duplicate tags are added even if multiple updates run concurrently. Which update operator should you use?

⚠ Common exam trap

The trap here is thinking $push can be used with a condition, or that $addToSet with $each is required for a single value.

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

✓

$addToSet

$addToSet is designed to add a value to an array only if it is not already present, making it the correct operator for ensuring uniqueness. It performs this check atomically, so concurrent updates will not introduce duplicates. $push would append duplicates, $set would replace the array, and $addToSet with $each is overkill for a single value.

Answer analysis

Option-by-option breakdown

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

  • ✗

    $addToSet with $each

    Why it's wrong here

    $addToSet with $each is used to add multiple values to an array, each only if not already present. However, for adding a single value, $addToSet alone is sufficient and simpler. Using $each is unnecessary and would still require the same operator. It is not incorrect but not the best choice for a single value.

  • ✗

    $push

    Why it's wrong here

    $push always appends the value to the array, even if it already exists, leading to duplicates. To avoid duplicates with $push, you would need to use the $each modifier with $addToSet, but that is not the same operator. $push alone does not satisfy the requirement to add only if not present.

  • ✓

    $addToSet

    Why this is correct

    $addToSet adds a value to an array only if it does not already exist in the array. It is idempotent and safe for concurrent updates because it checks for the value's presence as part of the atomic update. This ensures the tag "sale" is added only once, preventing duplicates.

  • ✗

    $set

    Why it's wrong here

    $set sets the value of a field to the specified value. If used on an array field, it would replace the entire array with the new value, not add an element. This would overwrite existing tags and is not appropriate for adding a single element conditionally.

About these practice questions

This C100DBA question is part of Courseiva's 222-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 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.