当我使用EnsureIndex时,我收到一条消息,
“所有索引都已存在”。
但在getIndexes()中什么都没有。为什么?有人能帮我吗?

mongos> db.UserBase.ensureIndex({"userId":1}, {"unique":true})
{
    "raw" : {
        "shard2/192.168.2.69:27024,192.168.254.107:27024,192.168.254.108:27024" : {
            "createdCollectionAutomatically" : false,
            "numIndexesBefore" : 2,
            "numIndexesAfter" : 2,
            "note" : "all indexes already exist",
            "ok" : 1,
            "$gleStats" : {
                "lastOpTime" : Timestamp(1468049378, 96),
                "electionId" : ObjectId("7fffffff0000000000000014")
            }
        }
    },
    "ok" : 1
}
mongos> db.UserBase.getIndexes()
[ ]

最佳答案

也许this能回答你的问题?
注意事项
在版本3.0.0中更改。
对于使用WiredTiger存储引擎的MongoDB 3.0部署,
如果从
mongo3.0之前的shell或3.0 compatible version之前的驱动程序版本,db.collection.getIndexes()将返回no
数据,即使存在现有索引。有关详细信息,请参见
WiredTiger and Driver Version Compatibility
尝试使用db.collection.createIndex()

07-28 02:42
查看更多