- Reference >
- Database Commands >
- Administration Commands >
- listIndexes
listIndexes¶
On this page
New in version 3.0.0.
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. The
mongo
shell provides thedb.collection.getIndexes()
helper.
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.
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: