[英]How to update _id in Mongodb Replica Set configuration?
I had 5 mongo members in Replica Set. 我在副本集中有5个mongo成员。 After I deleted 3 from it. 在我从中删除3后。
How can I change "_id" in others members to values "0", "1" and "2"? 如何将其他成员中的“ _id”更改为值“ 0”,“ 1”和“ 2”?
rs.conf()
{
"_id" : "rs0",
"version" : 151261,
"members" : [
{
"_id" : 3,
"host" : "mongodb3:27017"
},
{
"_id" : 4,
"host" : "mongodb4:27017"
},
{
"_id" : 5,
"host" : "ok:27017",
"arbiterOnly" : true
}
]
}
Directly editing the replica set configuration may not be an elegant way. 直接编辑副本集配置可能不是一个好方法。 Instead use the rs.remove(hostname)
command to remove a member from replica set , this way you need not have to bring down the primary during reconfiguration which will automatically assign ascending order values to "_id" field. 而是使用rs.remove(hostname)
命令从副本集中删除成员,这样,您无需在重新配置期间关闭主数据库,该数据库将自动将升序值分配给“ _id”字段。
Try dropping the slaves collection as described here: http://docs.mongodb.org/manual/tutorial/troubleshoot-replica-sets/#duplicate-key-error-on-local-slaves 尝试按照以下说明删除从属集合: http : //docs.mongodb.org/manual/tutorial/troubleshoot-replica-sets/#duplicate-key-error-on-local-slaves
The master will recreate the collection the next time it is required. 主服务器将在下次需要时重新创建该集合。
You could try this in the Mongo console: 您可以在Mongo控制台中尝试以下操作:
conf = rs.conf()
conf.members[0]._id = 0
conf.members[1]._id = 1
conf.members[2]._id = 2
rs.reconfig(conf)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.