Courseiva
Indexing →hardMultiple Select

C100DEV Indexing Practice Question

A developer is working with a collection 'products' that has an index { category: 1, price: 1 }. They want to understand how MongoDB can use this index for queries that include a sort on price. Which TWO of the following statements are true regarding the use of this index for sorting? (Choose two.)

⚠ Common exam trap

The trap here is assuming that a compound index can always provide a sort on any suffix field regardless of the predicates on the prefix 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 support a sort on price descending if the query includes an equality condition on category, by scanning the index in reverse.

The index { category: 1, price: 1 } can support sorting on price when the query includes an equality condition on category, because then the index's price entries are contiguous and sorted. It can also support a descending sort by scanning the index in reverse. Without an equality condition on category, the index cannot provide a global sort on price because the leading field category varies.

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 support a sort on price descending even if the query does not include any condition on category, because the index stores price in descending order when traversed in reverse.

    Why it's wrong here

    This is incorrect because the index is not globally sorted by price. It is sorted by category first, then price. Without an equality condition on category, the index cannot provide a global sort on price descending. Scanning in reverse would yield a global order by category descending and price descending within each category, which is not the same as a global price descending sort. An in-memory sort would still be required.

  • ✓

    The index can support a sort on price descending if the query includes an equality condition on category, by scanning the index in reverse.

    Why this is correct

    This is true because MongoDB can traverse an index in either direction. With an equality condition on category, the index entries for a given category are ordered by price ascending. To satisfy a sort on price descending, MongoDB can scan those entries in reverse order, avoiding an in-memory sort. This is a standard optimization.

  • ✓

    The index can support a sort on price ascending if the query includes an equality condition on category.

    Why this is correct

    This is true because when there is an equality predicate on category, the index's remaining field price is effectively sorted in ascending order (since the index is { category: 1, price: 1 }). The query can use the index to return results sorted by price ascending without an in-memory sort, as long as the equality condition on category is present.

  • ✗

    The index can support a sort on price ascending if the query includes a range condition on category, such as { category: { $gt: 'A' } }.

    Why it's wrong here

    This is false because a range condition on category does not fix the category to a single value. The index entries will be ordered by category first, and within each category by price. For a range of categories, the overall order is not by price globally. Therefore, the index cannot provide a sort on price ascending without an in-memory sort, even though it can be used for filtering on the category range.

  • ✗

    The index can support a sort on price ascending even if the query does not include any condition on category.

    Why it's wrong here

    This is false because without a condition on category, the index is ordered first by category and then by price within each category. A global sort on price would require merging results from multiple categories, which the index cannot provide directly. MongoDB would need an in-memory sort to order all documents by price across all categories, so the index alone cannot support the 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.