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.
totalDocsExaminedvsnReturned:- Ideal ratio is 1:1 (every document examined is returned).
- If
totalDocsExamined = 100,000andnReturned = 10, query is scanning 10,000 irrelevant documents!