Navigation

db.collection.getIndexes()

Definition

db.collection.getIndexes()

mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.

Returns an array that holds a list of documents that identify and describe the existing indexes on the collection. You must call db.collection.getIndexes() on a collection. For example:

db.collection.getIndexes()

Change collection to the name of the collection for which to return index information.

Behavior

Client Disconnection

Starting in MongoDB 4.2, if the client that issued the db.collection.getIndexes() disconnects before the operation completes, MongoDB marks the db.collection.getIndexes() for termination (i.e. killOp on the operation).

Required Access

The user executing the method requires either find privileges on the system.indexes collection or the listIndexes privilege action. At a minimum, the read built-in role provide the requisite permissions.

Output

db.collection.getIndexes() returns an array of documents that hold index information for the collection. Index information includes the keys and options used to create the index. For information on the keys and index options, see db.collection.createIndex().