06 / 18

How to list all indexes?

To list all indexes in a MongoDB collection, you can use the following methods:

  1. 1

    db.collectionName.getIndexes();

  2. 2

    db.runCommand({ listIndexes: 'collectionName' });

  3. 3

    If you are using MongoDB Compass (a graphical user interface for MongoDB), navigate to the collection, and under the 'Indexes' tab, you can view all existing indexes.