Courseiva
CRUD Operations →mediumMultiple Choice

C100DEV CRUD Operations Practice Question

You are designing an e-commerce catalog where products can have a dynamic array of tags. You need to query for documents where the 'tags' array contains both 'electronics' and 'sale' simultaneously, regardless of their order or other elements. Which query operator should you use?

⚠ Common exam trap

Candidates often mistakenly use the $in operator, which matches documents containing at least one of the values, rather than the $all operator, which requires all specified elements to exist.

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

✓

{ tags: { $all: ['electronics', 'sale'] } }

The $all operator selects the documents where the value of a field is an array that contains all the specified elements. This is essential when searching arrays for multiple matching criteria without enforcing strict positional indexing or exact array equality.

Answer analysis

Option-by-option breakdown

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

  • ✗

    { tags: { $in: ['electronics', 'sale'] } }

    Why it's wrong here

    The $in operator matches documents where the field value equals any value within the specified array. For array fields, it matches if the array contains at least one of the target values, failing the requirement to contain both.

  • ✓

    { tags: { $all: ['electronics', 'sale'] } }

    Why this is correct

    $all matches documents whose tags array contains every listed element, independent of order, duplicates or extra values. That precisely satisfies the requirement for simultaneous presence of both 'electronics' and 'sale', which a simple equality match cannot guarantee.

  • ✗

    { tags: ['$electronics', '$sale'] }

    Why it's wrong here

    This syntax is invalid: '$electronics' and '$sale' are parsed as field references, not string literals, and a bare array matches exact array equality including order and length. It is tempting because array literals resemble an 'in' list; it would be correct only when matching a document whose tags array equals exactly those two values.

  • ✗

    { tags: { $elemMatch: { $eq: 'electronics', $eq: 'sale' } } }

    Why it's wrong here

    $elemMatch matches a single array element satisfying all its criteria, so two $eq keys on the same field collapse to one condition, matching only 'sale'. It is tempting because $elemMatch is designed for arrays of subdocuments; it would be correct when each element is an object needing multiple field conditions.

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.