C100DBA · Question #104
Which of the following command is used to get all the indexes on a collection?
The correct answer is D. db.collection.getlndexesQ. db.collection.getIndexes() is the correct MongoDB method for retrieving all indexes defined on a collection, returning an array of index documents with their keys and options. Why the distractors are wrong: A (showIndexes()) - this method does not exist in MongoDB's collection…
Question
Which of the following command is used to get all the indexes on a collection?
Options
- Adb.collection.showIndexes()
- Bdb.collection.findlndexes()
- Cdb.showIndexes()
- Ddb.collection.getlndexesQ
How the community answered
(51 responses)- A2% (1)
- C4% (2)
- D94% (48)
Explanation
db.collection.getIndexes() is the correct MongoDB method for retrieving all indexes defined on a collection, returning an array of index documents with their keys and options.
Why the distractors are wrong:
- A (
showIndexes()) - this method does not exist in MongoDB's collection API. - B (
findIndexes()) - also non-existent; "find" is reserved for document queries, not index introspection. - C (
db.showIndexes()) - incorrect scope; you must call the method on a specific collection object, not directly on the database object.
Memory tip: Think "get what you need from the collection" - the pattern is always db.<collectionName>.getIndexes(). The word get signals retrieval of metadata, and since indexes belong to a collection (not the database), the method lives on the collection object, not db itself.
Topics
Community Discussion
No community discussion yet for this question.