Courseiva
Indexing →mediumMultiple Choice

C100DEV Indexing Practice Question

A collection 'orders' has a compound index { status: 1, customerId: 1, orderDate: -1 }. A developer runs a query: db.orders.find({ customerId: 'C123', status: 'shipped' }).sort({ orderDate: -1 }). Which statement about how MongoDB uses this index for the query is correct?

⚠ Common exam trap

The trap here is assuming that a sort field must be the first field of the index or that it cannot be used when equality conditions exist on preceding fields.

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 can be used for the equality filter on status and customerId, and it can also provide the sort on orderDate in descending order without an in-memory sort.

The compound index begins with status and customerId, both of which have equality conditions in the query. Since those fields are fixed, the index's remaining field orderDate is effectively ordered by its index direction. The query sorts by orderDate descending, matching the index direction, so MongoDB can use the index to satisfy both the filter and the sort without an in-memory sort stage.

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 can be used for the equality filter on status and customerId, and it can also provide the sort on orderDate in descending order without an in-memory sort.

    Why this is correct

    This is correct. The compound index prefix is { status: 1, customerId: 1 }, and both fields have equality conditions in the query. The third index field is orderDate: -1, and the query sorts by orderDate: -1. Since the equality fields are fixed to single values, the remaining index portion is ordered by orderDate descending, so MongoDB can use the index to return sorted results directly.

  • ✗

    The index cannot be used for this query because the query includes a sort on a field that is not the first field of the index.

    Why it's wrong here

    This is wrong because the position of the sort field in the index does not prevent index usage. The index can still be used for filtering on the leading equality fields, and because the sort field follows those equality fields in the index and matches the sort direction, it can also provide the sort order. The sort field does not need to be first in the index.

  • ✗

    The index can be used for the equality filter on status and customerId, but the sort on orderDate will require an in-memory sort because the index stores orderDate in ascending order only.

    Why it's wrong here

    This is false because the index stores orderDate in descending order (orderDate: -1). Even if it were ascending, MongoDB can traverse an index in reverse to satisfy a descending sort. The index is defined with orderDate: -1, and the query sorts by orderDate: -1, so the index can provide the sort without an in-memory sort stage.

  • ✗

    The index can be used for both the equality filter on status and customerId, but it cannot provide the sort order on orderDate because the sort field is not contiguous with the equality fields.

    Why it's wrong here

    This is incorrect because MongoDB can use the index to provide the sort. The query has equality predicates on status and customerId, which are the first two fields of the index. The remaining field orderDate is used for sorting in descending order, which matches the index order. Thus the index can support both filtering and sorting without an in-memory sort.

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.