C100DEV Indexing Practice Question
An IoT platform stores sensor readings in a collection `readings` with fields `deviceId`, `timestamp`, and `value`. The collection is large and grows continuously. Queries typically retrieve the most recent readings for a specific device, filtering by `deviceId` and sorting by `timestamp` descending. The operations team wants to minimize index size while still supporting these queries efficiently. Which index strategy best meets this requirement?
⚠ Common exam trap
The trap here is adding extra indexes such as a separate `timestamp` index or a hashed index, when a single well-ordered compound index already satisfies the equality filter and the sort.
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
✓
Create a compound index on { deviceId: 1, timestamp: -1 } only, which supports the equality filter and the descending sort without an additional index.
The query pattern filters by `deviceId` and sorts by `timestamp` descending. A compound index on `{ deviceId: 1, timestamp: -1 }` directly supports both the equality match and the sort, allowing MongoDB to return results in order without an in-memory sort. This single index is sufficient, minimizing index size and avoiding unnecessary additional indexes.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Create a hashed index on { deviceId: 1 } combined with a single-field index on { timestamp: -1 } to distribute data and support sorting.
Why it's wrong here
A hashed index on `deviceId` supports equality matches but does not preserve sort order, and it cannot be used for range queries. Combining it with a separate `timestamp` index still does not provide a compound sort for a specific device. This strategy adds complexity and storage without efficiently supporting the required query pattern.
- ✓
Create a compound index on { deviceId: 1, timestamp: -1 } only, which supports the equality filter and the descending sort without an additional index.
Why this is correct
A compound index on `{ deviceId: 1, timestamp: -1 }` matches the query pattern: equality on `deviceId` followed by a sort on `timestamp` descending. It allows MongoDB to locate the device's readings in sorted order directly from the index, avoiding an in-memory sort. No extra index is needed, which minimizes index size and maintenance.
- ✗
Create a compound index on { deviceId: 1, timestamp: -1 } and a separate single-field index on { timestamp: -1 } to handle global sorts.
Why it's wrong here
Adding a separate index on `timestamp` increases index storage and maintenance overhead. The queries described filter by `deviceId` and sort by `timestamp`, so the compound index alone supports them. The additional single-field index is unnecessary for the stated workload and contradicts the goal of minimizing index size.
- ✗
Create a single-field index on { deviceId: 1 } only, because the sort on `timestamp` can always be performed in memory efficiently.
Why it's wrong here
A single-field index on `deviceId` can filter documents but does not provide sorted order by `timestamp`. MongoDB would need to sort the matching documents in memory, which can be expensive and may exceed the memory limit for large result sets. This approach does not efficiently support the required sort and risks blocking sorts.
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 →
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.