intermediateTop 30 Scenario-Based Questions
Your MongoDB queries are slow on a 100-million document collection. How do you diagnose and fix?
1) Identify slow queries: db.setProfilingLevel(1, 100) (log queries > 100ms). 2) Check profile: db.system.profile.find().sort({millis:-1}).limit(5). 3) For each slow query: db.collection.find({...}).explain('executionStats'). 4) Look for: COLLSCAN (no index!) and totalDocsExamined >> nReturned. 5) Add missing indexes: if query is {status:'active', createdAt:{$gt:date}}: CREATE INDEX {status:1, cre
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
Your MongoDB queries are slow on a 100-million document collection. How do you diagnose and fix?