Open In App

MongoDB – getIndexes() Method

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. 

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.

db.student.getIndexes()

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()

Article Tags :