- Reference >
mongo
Shell Methods >- Collection Methods >
- db.collection.getIndexes()
db.collection.getIndexes()¶
On this page
Definition¶
-
db.collection.
getIndexes
()¶ mongo
Shell MethodThis 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, including hidden indexes. You must call
db.collection.getIndexes()
on a collection. For example: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).
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
.
Required Access¶
To run db.collection.getIndexes()
when access control is
enforced, usesrs must have privileges to listIndexes
on
the collection.
The built-in role read
provides the required privileges to
run db.collection.getIndexes()
for the collections in a
database.
Output¶
db.collection.getIndexes()
returns an array of documents that
hold index information for the collection. For example:
Note
Starting in MongoDB 4.4, db.collection.getIndexes()
no
longer includes the ns
field.
Index information includes the keys and options used to create the
index. The index option hidden
, available starting in MongoDB 4.4,
is only available if the value is true
.
For information on the keys and index options, see
db.collection.createIndex()
.