OPTIONS

Return a List of All Indexes

When performing maintenance you may want to check which indexes exist on a collection. In the mongo shell, you can use the getIndexes() method to return a list of the indexes on a collection.

See also

Index Concepts and Indexing Tutorials for more information about indexes in MongoDB and common index management operations.

List all Indexes on a Collection

To return a list of all indexes on a collection, use the db.collection.getIndexes() method or a similar method for your driver.

For example, to view all indexes on the people collection:

db.people.getIndexes()

List all Indexes for a Database

To list all indexes on all collections in a database, you can use the following operation in the mongo shell:

db.getCollectionNames().forEach(function(collection) {
   indexes = db[collection].getIndexes();
   print("Indexes for " + collection + ":");
   printjson(indexes);
});

MongoDB 3.0 deprecates direct access to the system.indexes collection.

For MongoDB 3.0 deployments using the WiredTiger storage engine, if you run db.getCollectionNames() and db.collection.getIndexes() from a version of the mongo shell before 3.0 or a version of the driver prior to 3.0 compatible version, db.getCollectionNames() and db.collection.getIndexes() will return no data, even if there are existing collections and indexes. For more information, see WiredTiger and Driver Version Compatibility.