C100DEV Indexing Practice Question
You are optimizing a collection containing user logs. Queries frequently filter by 'category' and sort by 'timestamp' in descending order. Which index configuration best supports these queries while maintaining efficiency?
⚠ Common exam trap
Candidates often violate the ESR rule by putting the sort field before the equality field in compound indexes, triggering costly in-memory sorts.
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
✓
{ category: 1, timestamp: -1 }
The ESR rule suggests placing Equality fields before Sort fields. By indexing { category: 1, timestamp: -1 }, MongoDB can filter by category and then traverse the index in the order specified for sorting. This eliminates the need for an in-memory sort stage, which is crucial for performance as the result set grows. Efficient index usage directly reduces memory consumption and prevents expensive blocking operations on the primary node.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
{ category: 1 }
Why it's wrong here
Indexing only the category field allows the engine to locate documents efficiently, but it fails to support the sort operation. Without the timestamp field in the index, MongoDB must perform an in-memory blocking sort, which is inefficient for large datasets and can exceed memory limits.
- ✗
{ timestamp: -1, category: 1 }
Why it's wrong here
This index structure does not follow the ESR rule. Placing the sort field before the equality field forces the database to scan more index entries than necessary. It fails to provide the optimal prefix for narrowing the search space based on the category, leading to slower query execution times.
- ✓
{ category: 1, timestamp: -1 }
Why this is correct
Following the ESR rule, this index places the equality field first and the sort field second. This structure allows MongoDB to jump directly to the category and use the pre-sorted order of the index to return the timestamped results, avoiding costly in-memory sorting operations during query execution.
- ✗
{ timestamp: -1 }
Why it's wrong here
This index is completely ineffective for filtering by category. The database would need to perform a full collection scan or scan the entire index to find matching categories, resulting in extremely poor performance. The query optimizer would likely ignore this index entirely for the specified filtering requirements.
About these practice questions
Courseiva writes every C100DEV question from scratch — 259 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 →
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.