- Reference >
- Database Commands >
- Administration Commands >
- listIndexes
listIndexes¶
On this page
Definition¶
-
listIndexes
¶ Returns information about the indexes on the specified collection. Returned index information includes the keys and options used to create the index. You can optionally set the batch size for the first batch of results.
Tip
In the mongo Shell, this command can also be run through the
db.collection.getIndexes()
helper method.Helper methods are convenient for mongo users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
Syntax¶
The command has the following form:
Command Fields¶
listIndexes
takes the following fields:
Field | Type | Description |
---|---|---|
listIndexes |
string | The name of the collection. |
cursor.batchSize |
integer | Optional. Specifies the cursor batch size. |
Required Access¶
If access control is enforced, the built-in read
role 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 listIndexes
disconnects before the operation completes, MongoDB marks listIndexes
for termination using killOp
.
Output¶
-
listIndexes.
cursor
¶ A result set returned in the batch size specified by your cursor. Each document in the batch output contains the following fields:
Field Type Description id integer A 64-bit integer. If zero, there are no more batches of information. If non-zero, a cursor ID, usable in a getMore
command to get the next batch of index information.ns string The database and collection name in the following format: <database-name>.<collection-name>
firstBatch document Index information includes the keys and options used to create the index.
Use
getMore
to retrieve additional results as needed.
-
listIndexes.
ok
¶ The return value for the command. A value of
1
indicates success.
Examples¶
List Database Indexes¶
In this example, you list indexes for the contacts
collection without
specifying the cursor batch size.
Your results will be similar to:
Specify Result Batch Size¶
In this example, you list indexes for the contacts
collection, and
specify a cursor batch size of 1.
Your results will be similar to:
Retrieve Additional Results¶
In this example, you use getMore
to retrieve additional result batches from
the contacts
collection.
Your results will be similar to: