Courseiva
Indexing →hardMultiple Choice

C100DEV Indexing Practice Question

An application writes documents to a `metrics` collection where each document contains an embedded array `samples` of subdocuments with fields `value` and `unit`. A query filters on `samples.unit` and `samples.value` together, expecting both conditions to match the same array element. The developer creates { "samples.unit": 1, "samples.value": 1 }. Which behavior should the developer expect from this index?

⚠ Common exam trap

The trap here is believing that indexing multiple paths inside one array preserves subdocument pairing, when multikey indexes flatten keys and lose element identity.

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

✓

The index is valid and can be used, but it may return documents where `unit` and `value` match different array elements unless the filter is written carefully.

Compound multikey indexes are allowed when the indexed paths belong to the same array, so the index can be created and used to reduce the candidate set. The critical limitation is that the index does not preserve element pairing: a document can match `samples.unit` and `samples.value` from different elements. Using `$elemMatch` restores the same-element requirement during document filtering.

Answer analysis

Option-by-option breakdown

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

  • ✗

    The index is automatically converted into a wildcard index covering all subdocument fields.

    Why it's wrong here

    MongoDB never silently converts an explicitly defined compound index into a wildcard index. Wildcard indexes must be created deliberately with the `$**` syntax. The declared index remains a compound multikey index on the two specified paths, and its behavior is governed by multikey rules, not wildcard semantics.

  • ✓

    The index is valid and can be used, but it may return documents where `unit` and `value` match different array elements unless the filter is written carefully.

    Why this is correct

    A compound multikey index on paths within one array is legal and useful for narrowing candidates. However, the index cannot guarantee that the matched `unit` and `value` belong to the same subdocument. To enforce same-element semantics, the query must use `$elemMatch`, which the planner evaluates after fetching the document.

  • ✗

    The index enforces that `unit` and `value` come from the same element, returning only matching pairs.

    Why it's wrong here

    Multikey indexes do not track element identity. The index stores separate keys for each array element's fields, so it cannot enforce that a `unit` key and a `value` key originated from the same subdocument. The planner may use the index to narrow candidates, but the final filter still evaluates the array semantics during document fetch.

  • ✗

    The index cannot be created because compound multikey indexes are disallowed on array fields.

    Why it's wrong here

    MongoDB permits compound multikey indexes as long as at most one indexed field in the compound key is an array. Here both indexed paths point into the same array `samples`, which is allowed. The restriction applies to two distinct array fields, not to two paths within one array.

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.