Courseiva
Indexing →hardMultiple Choice

C100DEV Indexing Practice Question

A financial analytics collection stores documents with fields 'accountId' (string), 'transactionDate' (date), and 'amount' (decimal). A common query is: db.transactions.find({ accountId: 'A123', transactionDate: { $gte: ISODate('2024-01-01'), $lte: ISODate('2024-01-31') }, amount: { $gt: 1000 } }). You need an index that supports this query efficiently. Following the ESR rule, which index key pattern is optimal?

⚠ Common exam trap

The trap here is assuming that the order of range fields does not matter, when in fact placing the equality field first and choosing a sensible range order affects how many index keys are scanned.

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

✓

{ accountId: 1, transactionDate: 1, amount: 1 }

The query contains an equality on accountId and range predicates on transactionDate and amount, with no explicit sort. The ESR rule dictates that equality fields come first, then sort fields (none here), then range fields. Placing the equality field accountId first allows a direct seek, and ordering the range fields transactionDate then amount lets the index scan the date range efficiently while filtering amount as a residual index condition. This reduces keys examined and avoids a collection scan.

Answer analysis

Option-by-option breakdown

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

  • ✗

    { accountId: 1, amount: 1 } and a separate index on transactionDate

    Why it's wrong here

    A compound index missing transactionDate cannot support the date range predicate as an index bound; it would need to scan all amounts for the account and filter dates in memory. A separate index on transactionDate might be used for the date range, but MongoDB generally selects one index per query (unless using index intersection, which is limited and not reliable here). This approach is less efficient than a single compound index covering equality and both ranges.

  • ✓

    { accountId: 1, transactionDate: 1, amount: 1 }

    Why this is correct

    The query has an equality on accountId, a range on transactionDate, and a range on amount. With no sort specified, the ESR rule places the equality field first, then the range fields. Ordering transactionDate before amount allows the index to seek to the account and then scan the date range; amount is evaluated as an index filter on the remaining entries. This minimizes keys examined and avoids a full collection scan.

  • ✗

    { transactionDate: 1, accountId: 1, amount: 1 }

    Why it's wrong here

    Leading with transactionDate means the index is primarily ordered by date across all accounts. For an equality on accountId, MongoDB cannot seek directly to the account; it must scan the date range across many accounts and filter by accountId. This increases keys examined significantly compared to putting the equality field first, making it a poor choice for this query pattern.

  • ✗

    { accountId: 1, amount: 1, transactionDate: 1 }

    Why it's wrong here

    This index orders by accountId, then amount, then transactionDate. The range predicate on amount appears before the range on transactionDate, which means the index cannot efficiently use transactionDate for a range scan after the amount range; it would have to scan all amounts for the account and filter dates. The ESR rule requires equality fields first, then sort fields, then range fields, so placing amount before transactionDate is suboptimal.

About these practice questions

One of 259 original C100DEV practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.