C100DBA · Question #39
What does the totalKeysExamined field returned by the explain method indicate?
The correct answer is B. Number of index entries scanned. totalKeysExamined counts the number of index entries (keys) MongoDB scanned while executing the query - it tells you how efficiently an index was used, since a high value relative to documents returned signals a poorly selective index. Option A (totalDocsExamined or nReturned)…
Question
What does the totalKeysExamined field returned by the explain method indicate?
Options
- ANumber of documents that match the query condition
- BNumber of index entries scanned
- CDetails the completed execution of the winning plan as a tree of stages
- DNumber of documents scanned
How the community answered
(61 responses)- A5% (3)
- B87% (53)
- C7% (4)
- D2% (1)
Explanation
totalKeysExamined counts the number of index entries (keys) MongoDB scanned while executing the query - it tells you how efficiently an index was used, since a high value relative to documents returned signals a poorly selective index. Option A (totalDocsExamined or nReturned) tracks matching documents, not index entries. Option D (totalDocsExamined) is a separate field that counts full document scans, which only happens after the index scan narrows candidates. Option C describes the executionStats.executionStages or queryPlanner.winningPlan field, which is a structural tree - not a numeric counter at all.
Memory tip: Think "Keys = Index" - an index is essentially a sorted list of keys, so totalKeysExamined is how many of those key slots MongoDB stepped through. If totalKeysExamined far exceeds nReturned, your index isn't selective enough.
Topics
Community Discussion
No community discussion yet for this question.