Facebook Pixel

What is a covered query in MongoDB?

A query where all the fields you need are in the index. MongoDB returns results from the index without fetching the document. The plan shows a PROJECTION_COVERED stage. Fastest. Use .select() to limit fields and ensure the index covers them.

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.

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?

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.