Courseiva
Indexing and Performance →hardMultiple Choice

C100DBA Indexing and Performance Practice Question

A DBA is reviewing a query that performs a sort on a field named score in descending order. The collection has an index { score: 1 }. The query also includes a filter on a field named active with an equality condition. The DBA observes that the query planner chooses a collection scan and performs an in-memory sort. Which index would allow the query to use an index for both the filter and the sort?

⚠ Common exam trap

The trap here is assuming that an index on the sort field alone is sufficient, when the equality filter field should precede the sort field for efficient compound index usage.

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

✓

{ active: 1, score: -1 }

The query filters on active with equality and sorts by score descending. The optimal index places the equality field first and the sort field second in the matching direction: { active: 1, score: -1 }. This allows MongoDB to use the index for the filter and to provide the descending sort order directly, avoiding an in-memory sort and improving performance.

Answer analysis

Option-by-option breakdown

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

  • ✗

    { score: -1, active: 1 }

    Why it's wrong here

    This index leads with score in descending order, which matches the sort, but the equality filter on active is placed after score. MongoDB can use the index to provide the sort order, but it cannot efficiently filter on active because active is not a prefix of the index. It would have to scan all score values and filter active as a residual predicate, which is less efficient than placing the equality field first. The query planner may still choose a collection scan if the filter is selective.

  • ✗

    { score: 1, active: 1 }

    Why it's wrong here

    This index leads with score ascending and places active second. It does not efficiently support the equality filter on active because active is not a prefix. It also provides score in ascending order, while the query sorts descending. MongoDB could reverse scan the index for the sort, but the filter on active would still be a residual predicate applied after scanning many score values. This index is not optimal for the query pattern.

  • ✗

    { active: 1, score: 1 }

    Why it's wrong here

    This index has active first, which is good for the equality filter, but score is ascending. The query sorts by score descending. MongoDB can traverse an ascending index in reverse to satisfy a descending sort, so this index could potentially support the sort. However, the question asks for an index that allows both filter and sort; the ascending index on score would require a reverse scan, which is possible but may not be as optimal as a directly matching descending index. In practice, MongoDB can use either, but the descending index is a more direct match.

  • ✓

    { active: 1, score: -1 }

    Why this is correct

    The query has an equality filter on active and sorts by score descending. An index with active first (equality) and score second in descending order allows MongoDB to filter on active and then scan the index in score descending order. This satisfies both the filter and the sort without an in-memory sort. The leading equality field ensures the index can be used efficiently for the filter, and the sort field follows in the correct direction.

About these practice questions

Courseiva writes every C100DBA question from scratch — 222 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.