Q52 [Scenario]: An API endpoint fetching user activity logs takes 8 seconds. Walk through your step-by-step debugging workflow.
- Enable Database Profiler:
db.setProfilingLevel(1, { slowms: 100 })to log slow operations tosystem.profile. - Extract Explain Plan: Run
.explain('executionStats')on the offending query. - Inspect Stages: Check if
winningPlanshowsCOLLSCAN. Look attotalDocsExaminedvsnReturned. - Apply Indexing: Construct a compound index adhering to the ESR rule (
Equality, Sort, Range). - Verify: Re-run explain to verify
IXSCANstage execution.
Key Takeaways
Identify slow queries via system profiler or MongoDB Atlas Performance Advisor.
Apply ESR rule indexing to convert
COLLSCANintoIXSCAN.
Knowledge Check
Which system collection stores slow operation entries when database profiling is enabled?