Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

MongoDB – getIndexes() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

My Personal Notes arrow_drop_up
Last Updated : 05 Feb, 2021
Like Article
Save Article
Similar Reads
Related Tutorials