【问题标题】:How to test if an index is unique in Mongo on the command line如何在命令行上测试索引在 Mongo 中是否唯一
【发布时间】:2011-09-21 06:06:44
【问题描述】:

我正在使用其他人创建的集合,我需要确定索引是否唯一。无论如何可以从 mongo shell 执行此操作吗?

【问题讨论】:

标签: mongodb


【解决方案1】:

您可以通过以下方式搜索索引:

db.system.indexes.find();

要搜索唯一索引:

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

这样,您还可以添加更多搜索参数,以按命名空间、键等查找特定索引。

编辑:相关文档:http://www.mongodb.org/display/DOCS/Index-Related+Commands

【讨论】:

  • @Sentinel:什么是“这个”?他发布了 2 条建议。
【解决方案2】:
db.<my_collection>.getIndexes()

如果其中一些索引是唯一的,您将看到一个名为“unique”的键,其值为 true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多