Recall & Review
beginner
What is the purpose of using indexes in MongoDB?
Indexes help MongoDB find data faster by creating a quick lookup for fields, similar to an index in a book.
Click to reveal answer
beginner
Which MongoDB command shows how a query uses indexes?
The
explain() method shows details about how MongoDB executes a query and which indexes it uses.Click to reveal answer
intermediate
What does the
winningPlan field in explain() output indicate?It shows the best plan MongoDB chose to run the query, including which index it used if any.
Click to reveal answer
intermediate
How can you verify if a query is using a collection scan instead of an index?
If
explain() shows COLLSCAN in the stage, it means MongoDB scanned the whole collection without using an index.Click to reveal answer
advanced
Why might MongoDB choose not to use an index even if one exists?
MongoDB may skip an index if it thinks scanning the whole collection is faster, for example if the query returns many documents.
Click to reveal answer
Which MongoDB method helps you check if a query uses an index?
✗ Incorrect
The explain() method shows how MongoDB runs a query and which indexes it uses.
What does a
COLLSCAN stage in explain() output mean?✗ Incorrect
COLLSCAN means MongoDB scanned all documents without using an index.
If a query returns many documents, MongoDB might:
✗ Incorrect
MongoDB may skip indexes if scanning the collection is faster for large result sets.
Which field in
explain() output shows the chosen query plan?✗ Incorrect
queryPlanner.winningPlan shows the plan MongoDB picked to run the query.
To see all indexes on a MongoDB collection, you use:
✗ Incorrect
listIndexes() lists all indexes on a collection.
Explain how to verify if a MongoDB query uses an index and what to look for in the explain output.
Think about the query plan and stages shown by explain()
You got /4 concepts.
Describe why MongoDB might choose not to use an index even if one exists for a query.
Consider query performance and optimizer decisions
You got /4 concepts.