How to test if an index is unique in Mongo on the command line
I'm working with a collection t开发者_Go百科hat someone else created, and I need to find out whether an index is unique. Is there anyway to do this from the mongo shell?
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
db.<my_collection>.getIndexes()
If some of those indexes are unique, you will see a key named "unique" with the value true.
精彩评论