db.collection.getIndexes()
Definition
mongo
Shell Method
This page documents the mongo
shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.
Returns an array that holds a list of documents that identify anddescribe the existing indexes on the collection. You must calldb.collection.getIndexes()
on a collection. For example:
- db.collection.getIndexes()
Change collection
to the name of the collection for which toreturn index information.
Considerations
Changed in version 3.0.0.
For MongoDB 3.0 deployments using the WiredTiger storage engine, if you run db.collection.getIndexes()
from aversion of the mongo
shell before 3.0 or a version of thedriver prior to 3.0 compatible version, db.collection.getIndexes()
will return no data, even ifthere are existing indexes. For more information, seeWiredTiger and Driver Version Compatibility.
Behavior
Client Disconnection
Starting in MongoDB 4.2, if the client that issued the db.collection.getIndexes()
disconnects before the operation completes, MongoDB marksthe db.collection.getIndexes()
for termination (i.e. killOp
on theoperation).
Required Access
The user executing the method requires either find
privileges on the system.indexes
collection or thelistIndexes
privilege action. At a minimum, theread
built-in role providethe requisite permissions.
Output
db.collection.getIndexes()
returns an array of documents thathold index information for the collection. Index information includesthe keys and options used to create the index. For information on thekeys and index options, see db.collection.createIndex()
.