A list of indices in MongoDB?
Solution 1:
From the shell:
db.test.getIndexes()
For shell help you should try:
help;
db.help();
db.test.help();
Solution 2:
If you want to list all indexes across collections:
db.getCollectionNames().forEach(function(collection) {
indexes = db.getCollection(collection).getIndexes();
print("Indexes for " + collection + ":");
printjson(indexes);
});
Solution 3:
And if you want to get list of all indexes in your database:
use "yourdbname"
db.system.indexes.find()
Solution 4:
Make sure you use your collection:
db.collection.getIndexes()
http://docs.mongodb.org/manual/administration/indexes/#information-about-indexes
Solution 5:
You can also output all your indexes together with their size:
db.collectionName.stats().indexSizes
Also check that db.collectionName.stats()
gives you a lot of interesting information like paddingFactor, size of the collection and number of elements inside of it.