【发布时间】:2017-01-26 10:03:11
【问题描述】:
我最近在 Mongo 2.6 副本集中看到了这个错误:
WARNING: the collection 'mydatabase.somecollection' lacks a unique index on _id. This index is needed for replication to function properly.
我假设 _id 索引默认是唯一的。但我正在尝试检查/设置它。 getIndexes 显示没有唯一的选项集。
> db.somecollection.getIndexes()[0]
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mydatabase.somecollection",
"name" : "_id_"
}
> db.somecollection.ensureIndex({"_id":1},{unique:true})
> { "numIndexesBefore" : 3, "note" : "all indexes already exist", "ok" : 1 }
> db.somecollection.getIndexes()[0]
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mydatabase.somecollection",
"name" : "_id_"
}
我试过.validate(true):
...
"valid" : true,
"errors" : [ ],
"ok" : 1
}
还有.reIndex() 运行没有错误。我无法删除 _id 索引来重新创建它 - 如何将索引设置为唯一或我应该怎么做才能确保 RS 中的数据一致性?请注意,RS 已按照 2.2 --> 2.4 --> 2.6 的升级说明进行升级。我找到了这个MongoDB - Collection lacks a unique index on _id,但那里没有任何东西可以解决我的问题。
【问题讨论】:
标签: mongodb