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.
- 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.
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.
In the following examples, we are working with:
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:
- Create an index using createIndex() method:
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.
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!