Reputation: 1873
I know db.collection.getIndexes()
can return all the indexes in collection
, but sometimes it will return a long result if collection
has many indexes, and this will make it difficult for you to find whether a certain field is indexed.
So how can you check whether a certain field is indexed in mongodb?
Upvotes: 1
Views: 2136
Reputation: 6008
Yes, you can easily view whether you field is indexed or not using below query:
db.collection.stats().indexSizes().c2_YOUR_FIELD_NAME
In above query, use your own collection name and field name. If it returns some value on console, the field is indexed.
THIS will give you much indepth-knowhow
Upvotes: 3