Navigation

listIndexes

Definition

listIndexes

Returns information about the indexes on the specified collection, including hidden indexes. Specifically, the command returns a document that contains information with which to create a cursor to the index information. Index information includes the keys and options used to create the index. The mongo shell provides the db.collection.getIndexes() helper.

The command has the following form:

{ "listIndexes": "<collection-name>" }
Field Type Description
listIndexes string The name of the collection.
comment any

Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:

A comment can be any valid BSON type (string, integer, object, array, etc).

New in version 4.4.

Required Access

To run listIndexes when access control is enforced, users must have privileges to listIndexes. The built-in role read provides the required privileges to run listIndexes for the collections in a database.

Behavior

Client Disconnection

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

Replica Set Member State Restriction

Starting in MongoDB 4.4, to run on a replica set member, listIndexes operations require the member to be in PRIMARY or SECONDARY state. If the member is in another state, such as STARTUP2, the operation errors.

In previous versions, the operations can also be run when the member is in STARTUP2. However, the operations wait until the member transitions to RECOVERING.

Output

listIndexes.cursor

A document that contains information with which to create a cursor to index information. The cursor information includes the cursor id, the full namespace for the command, as well as the first batch of results. Index information includes the keys and options used to create the index. The index option hidden, available starting in MongoDB 4.4, is only present if the value is true.

For information on the keys and index options, see db.collection.createIndex().

listIndexes.ok

The return value for the command. A value of 1 indicates success.

←   listDatabases logRotate  →