C100DBA practice question 1 of 25

If the value of totalKeysExamined is 30000 and the value of totalDocsExamined is 0, which of the following option is correct?

Full set: 130 questions
Answer options
A: None of the above
B: The query used an index to fetch the results Correct answer
C: The query returned 0 documents
D: The query returned 30000 documents after scanning the documents
Correct Answer:
B. The query used an index to fetch the results
Explanation

The executionStats values indicate the query's performance. totalKeysExamined: 30000 confirms that the query planner selected and used an index, scanning 30,000 index entries. totalDocsExamined: 0 means that MongoDB did not need to access the actual documents in the collection to fulfill the query. This scenario describes a "covered query," where all the fields required for both the query filter and the returned projection are present in the index itself. Therefore, the query definitely used an index.

Why Incorrect

A. Option B is a correct and direct conclusion that can be drawn from the provided query execution statistics.
C. We cannot determine the number of returned documents (nReturned) from the given information; a covered query can return results.
D. The query scanned zero documents (totalDocsExamined: 0), not 30,000. totalKeysExamined is the count of index entries scanned.

References

- MongoDB Manual, explain() Results, executionStats. The documentation defines totalKeysExamined as the "Number of index entries scanned" and totalDocsExamined as the "Number of documents examined."

- MongoDB Manual, Query Optimization, "Covered Query". This section explains that a covered query is one that can be satisfied entirely using an index, resulting in totalDocsExamined being 0.

- MongoDB University, M201 MongoDB Performance, Chapter 2, "Using Indexes", Video "Covered Queries". This lesson details how covered queries work and how to identify them using the explain plan.

Scroll to Top