C100DBA practice question 4 of 25

What does the totalKeysExamined field returned by the explain method indicate?

Full set: 130 questions
Answer options
A: Number of documents that match the query condition
B: Number of index entries scanned Correct answer
C: Details the completed execution of the winning plan as a tree of stages
D: Number of documents scanned
Correct Answer:
B. Number of index entries scanned
Explanation

The totalKeysExamined field is a crucial metric within the executionStats section of an explain() plan's output. It quantifies the number of index entries that MongoDB scanned to fulfill the query. A lower value for totalKeysExamined relative to the number of documents returned (nReturned) generally indicates a more efficient index usage, as the database had to inspect fewer index keys to locate the target documents. This metric is essential for diagnosing and optimizing query performance.

Why Incorrect

A: The number of documents that match the query condition and are returned to the client is indicated by the nReturned field. C: This describes the executionStages object, which provides a detailed, hierarchical view of the operations performed during query execution. D: The number of documents scanned from the collection after being identified via the index is reported in the totalDocsExamined field.

References

1. MongoDB Manual, "Explain Results". In the executionStats section, executionStats.totalKeysExamined is defined as the "Number of index entries scanned." (https://www.mongodb.com/docs/manual/reference/explain-results/#mongodb-explain-field-executionStats.totalKeysExamined)

2. MongoDB Manual, "Analyze Query Performance". This page explains how to use totalKeysExamined and totalDocsExamined to evaluate query efficiency. (https://www.mongodb.com/docs/manual/tutorial/analyze-query-performance/)

Scroll to Top