- Reference >
mongo
Shell Methods >- Collection Methods >
- db.collection.getIndexes()
db.collection.getIndexes()¶
On this page
Definition¶
-
db.collection.
getIndexes
()¶ Important
mongo
Shell MethodThis page documents a
mongo
method. This is not the documentation for database commands or language-specific drivers, such as Node.js. To use the database command, see thelistIndexes
command.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
Returns an array that holds a list of documents that identify and describe the existing indexes on the collection. You must call
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 db.collection.getIndexes()
disconnects before the operation completes, MongoDB marks db.collection.getIndexes()
for termination using killOp
.
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. Index information includes
the keys and options used to create the index. For information on the
keys and index options, see db.collection.createIndex()
.