1

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?

SAUMYA
  • 1,508
  • 1
  • 13
  • 20
Daniel
  • 1,783
  • 2
  • 15
  • 25
  • 1
    This should help? http://stackoverflow.com/questions/35019313/checking-if-an-index-exists-in-mongodb – KaSh May 16 '16 at 07:59

1 Answers1

3

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

Ankur Soni
  • 5,725
  • 5
  • 50
  • 81