Q52 [Scenario]: An API endpoint fetching user activity logs takes 8 seconds. Walk through your step-by-step debugging workflow.

  1. Enable Database Profiler: db.setProfilingLevel(1, { slowms: 100 }) to log slow operations to system.profile.
  2. Extract Explain Plan: Run .explain('executionStats') on the offending query.
  3. Inspect Stages: Check if winningPlan shows COLLSCAN. Look at totalDocsExamined vs nReturned.
  4. Apply Indexing: Construct a compound index adhering to the ESR rule (Equality, Sort, Range).
  5. Verify: Re-run explain to verify IXSCAN stage execution.
Key Takeaways
  • Identify slow queries via system profiler or MongoDB Atlas Performance Advisor.

  • Apply ESR rule indexing to convert COLLSCAN into IXSCAN.

Knowledge Check

Which system collection stores slow operation entries when database profiling is enabled?