7

I'm working with a collection that someone else created, and I need to find out whether an index is unique. Is there anyway to do this from the mongo shell?

dave
  • 12,406
  • 10
  • 42
  • 59
  • possible duplicate of [A list of indices in MongoDB?](http://stackoverflow.com/questions/2789865/a-list-of-indices-in-mongodb) –  Jun 23 '11 at 13:53

2 Answers2

10

You can search for indexes with:

db.system.indexes.find();

To search for a unique index:

db.system.indexes.find({"unique": true});

With that, you can also add more search parameters to find specific indexes by namespace, key, etc.

Edit: Relevant documentation: http://www.mongodb.org/display/DOCS/Index-Related+Commands

Andz
  • 2,228
  • 19
  • 13
7
db.<my_collection>.getIndexes()

If some of those indexes are unique, you will see a key named "unique" with the value true.

Manur
  • 8,436
  • 2
  • 27
  • 29