开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜