MongoDB World 2019: The Sights (and Smells) of a Bad Query
“Why is MongoDB so slow?” you may ask yourself on occasion. You’ve created indexes, you’ve learned how to use the aggregation pipeline. What the heck? Could it be your queries? This talk will outline what tools are at your disposal (both in MongoDB Atlas and in MongoDB server) to identify inefficient queries.
A code smell is any characteristic in the source code of
a program that possibly indicates a deeper problem.
Code smells are usually not bugs; they are not technically incorrect and
do not prevent the program from functioning.
Instead, they indicate weaknesses in design that may slow down
development or increase the risk of bugs or failures in the future.
• Atlas M10 Cluster
• 2-3M documents
• Generated and imported
using a template
• Ran some adhoc queries
Let’s find some data – in order this time
• Looking for everyone older than
25 from Utah, sorted by name
• IXSCAN …. But slow
• Far more keys and documents
examined than returned (we’ll
come back to this one)
• In memory sort!
What can stink?
• Alerts (from Atlas, Ops Manager, Cloud Manager)
• COLLSCAN (in logs or explain plans)
• SORT (in explain plans or in logs as hasSortStage)
• Non-ESR Compound Indexes
• Sharp rise in one or more metrics (in Atlas, Ops Manager or
• Queries slower than slowms
• Large docsExamined/n ratio
Notes/links from this talk available at: