Facebook Pixel

What does COLLSCAN mean in explain()?

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).

Verify This Answer

Cross-check this information using these trusted sources:

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.

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.

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).

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.