Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Mongo, how do I display the indexes of a collection? [duplicate]

I just want to display all the indexes in the shell.

like image 421
TIMEX Avatar asked Dec 19 '10 04:12

TIMEX


People also ask

How do I view indexes in MongoDB?

Finding indexes You can find all the available indexes in a MongoDB collection by using the getIndexes method. This will return all the indexes in a specific collection. Result: The output contains the default _id index and the user-created index student name index.

Which of the following command is used to get all the indexes on collection?

List All Indexes on a Collection. To return a list of all indexes on a collection, use the db. collection. getIndexes() method or a similar method for your driver .

Which method do you use to verify the indexes MongoDB uses when executing a query?

In MongoDB, you can use the cursor. explain() method or the db. collection. explain() method to determine whether or not a query uses an index.


1 Answers

If you want raw access to the indexes, you can query the db.system.indexes collection:

> db.system.indexes.find() 

To find the indexes for a specific collection, you can do:

> db.collection.getIndexes() 

See this question.

like image 77
Cameron Avatar answered Sep 21 '22 14:09

Cameron