0
0
MongoDBquery~5 mins

Index usage verification in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aexplain()
BfindIndex()
CshowIndexes()
DlistIndexes()
What does a COLLSCAN stage in explain() output mean?
AQuery used a cached result
BQuery used an index
CQuery failed
DQuery scanned the entire collection
If a query returns many documents, MongoDB might:
AAlways use an index
BThrow an error
CSkip the index and scan the collection
DCreate a new index automatically
Which field in explain() output shows the chosen query plan?
AqueryPlanner.winningPlan
BexecutionStats.totalDocsExamined
CserverStatus
DindexStats
To see all indexes on a MongoDB collection, you use:
Adb.collection.getIndexes()
Bdb.collection.listIndexes()
Cdb.collection.showIndexes()
Ddb.collection.explain()
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.