Skip to main content
InterviewHubPRO
Section Overview
Q26

Question 26 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

52%
MongoDB & NoSQL (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

How do you analyze query performance using `explain("executionStats")`?

senior LevelFormsPerformance

In Simple Words: Run db.collection.find(...).explain("executionStats"):

  • executionStages.stage:
    • IXSCAN: Good! Index scan utilized.
    • FETCH: Fetching full documents from disk based on index.
    • COLLSCAN: Fatal Full Collection Scan! Missing index.
  • totalDocsExamined vs nReturned:
    • Ideal ratio is 1:1 (every document examined is returned).
    • If totalDocsExamined = 100,000 and nReturned = 10, query is scanning 10,000 irrelevant documents!