In MongoDB, the getIndexes() method returns an array that contains a list of documents that identify and describe the existing indexes on the specified collection. It also includes hidden indexes as well.
- This method does not take any parameters.
- The index information return by this method contains the keys and the options used to create an index.
- In this method, the hidden index available starting from MongoDB 4.4. Only if the value is true.
Syntax:
db.Collection_name.getIndexes()
Return:
This method returns an array that contains a list of documents that identify and describe the existing indexes on the specified collection. It also includes hidden indexes as well.
Examples:
In the following examples, we are working with:
Database: gfg
Collection: student
Documents: Three documents contains name and the language in which the students are interested.

- Return an array of documents that hold index information for the student collection:
db.student.getIndexes()

- Create an index using createIndex() method:
db.student.createIndex({name:1, language:-1})
Here, we first create an index using createIndex() method.

After creating a new index we use greateIndex() method to find the index information for the student collection.
db.student.getIndexes()

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Feb, 2021
Like Article
Save Article