C100DEV MongoDB Overview and Document Model Practice Question
A development team is designing a MongoDB collection to store sensor readings. Each reading document contains a `sensorId`, a `timestamp`, and a `value`. The team expects billions of readings and needs to optimize for fast queries that retrieve the latest reading for a specific sensor. They decide to use a compound index. Which index key order best supports this query pattern?
⚠ Common exam trap
The trap here is assuming that the timestamp field should come first because it is used in sorting, but the equality filter on sensorId must precede the sort field in the index.
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
✓
{ sensorId: 1, timestamp: -1 }
The optimal compound index for retrieving the latest reading per sensor is `{ sensorId: 1, timestamp: -1 }`. This allows MongoDB to seek directly to the sensor's entries and return them in descending time order, so the first result is the most recent. It also supports equality on sensorId and sort on timestamp, enabling an efficient, non-blocking query.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
{ timestamp: 1, sensorId: 1 }
Why it's wrong here
This index orders primarily by timestamp, which means queries filtering on a specific sensorId would need to scan many index entries across all timestamps. For retrieving the latest reading for a given sensor, the query would have to examine all timestamps for that sensor, making it inefficient. The sensorId should come first to allow direct lookup.
- ✗
{ value: 1, sensorId: 1 }
Why it's wrong here
Indexing on value first does not help with queries that filter by sensorId and sort by timestamp. The query pattern requires efficient retrieval by sensor and time, not by value. This index would only be useful for queries that filter or sort on value, which is not the primary access pattern described.
- ✗
{ sensorId: 1, value: 1 }
Why it's wrong here
While sensorId first is good, the second key is value, not timestamp. The query needs to sort by timestamp to get the latest reading. This index would not provide the correct sort order, forcing an in-memory sort after fetching all readings for the sensor, which is inefficient for large datasets.
- ✓
{ sensorId: 1, timestamp: -1 }
Why this is correct
Placing sensorId first allows the index to quickly locate all readings for a specific sensor. The descending timestamp then orders those readings from newest to oldest, so the first entry for that sensor is the latest reading. This supports an efficient query using `find({ sensorId: X }).sort({ timestamp: -1 }).limit(1)` with a covered index scan.
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 →
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.