db.collection.getIndexes() is the mongosh method used to return the definitions of all indexes that currently exist on a collection. The result is an array of index specification documents that can show fields such as the index name, key pattern, index version, uniqueness, partial-filter settings, sparse configuration, collation, and whether the index is hidden. This makes the method useful for index audits, troubleshooting, and confirming the physical indexes available to the query planner. Option A is not a documented method for enumerating collection indexes. Option B resembles the $indexStats aggregation stage, which reports usage statistics for indexes, but db.collection.indexStats() is not the method used to list full index definitions. Option C, findIndexes(), is also not the documented mongosh collection helper. Administrators should distinguish between listing index definitions, examining index usage, and inspecting an individual query ' s winning plan: getIndexes() addresses the first requirement, $indexStats addresses usage metrics, and explain() addresses query-planner behavior. Therefore option D is the correct command for listing all indexes on the collection.
Study Guide reference/topic:Indexing and Query Optimization - index administration, index metadata, and db.collection.getIndexes().
===========
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit