MongoDB is sorting in memory. Can be slow for large result sets. Add an index that matches your sort order to remove the SORT stage. The index should include the sort field (and the filter field, as a compound index).
MongoDB explain() Plan Explained: How to Read It
What does a SORT stage mean in explain()?
The answer
More FAQs in MongoDB explain() Plan Explained: How to Read It
User.find({ email }).explain('executionStats'). Three modes: queryPlanner (just the plan), executionStats (runs the query, includes stats), allPlansExecution (stats for all candidate plans). Use executionStats for optimization.
Collection scan. MongoDB reads every document in the collection. Bad for performance. Add an index on the filter field to switch to IXSCAN (index scan).
Index scan. MongoDB uses an index to find documents. Good. Check executionStats.totalDocsExamined and totalKeysExamined; both should be close to the number of documents returned.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.