Not all slow MongoDB queries are bad queries.
Sometimes the query is fine, but MongoDB does not have a good index to help with your filtering, sorting, and retrieving of the data
In this tutorial, we'll use payments as an example of our database. The collection starts without a useful index for our query. We'll identify the slow operation, learn about the recommended index, explain why the compound index works, and manage it visually in VisuaLeaf .
The workflow is simple:
slow query -> query profiler -> index recommendation -> compound index -> index manager
You can use the same workflow when your own MongoDB collections start to feel slow.
On this page
The Slow Query Problem
The Payments Query We Want to Optimize
Find the Slow Query in VisuaLeaf
Read the Index Recommendation
Why This Compound Index Works
Check and Manage Indexes
Indexing Mistakes to Avoid
FAQ
The Slow Query Problem
MongoDB can return results quickly when a collection is small.
But as the collection grows, the same query can…