要重命名MongoDB副本集,必须关闭副本集的所有节点,然后使用新的副本集名称配置每个节点的 local数据库。
该程序需要停机。
先决条件
确保副本集未分片。重命名过程仅适用于未分片的副本集。
在重命名副本集之前,请执行完整的 MongoDB 部署备份。
步骤
2
重命名副本集。
对每个副本集节点执行以下步骤:
在不使用
--replSet选项的其他端口上启动副本集成员。更新副本集名称。
如果使用的是配置文件,请将
replication.replSetName设置为新名称。
连接到副本集成员。
使用以下命令更新本地数据库中的副本集名称:
/* Set `newId` to the new replica set name */ var newId = '<new replica set name>' var doc = db.getSiblingDB("local").system.replset.findOne() var oldId = doc._id doc._id = newId db.getSiblingDB("local").system.replset.insertOne(doc) db.getSiblingDB("local").system.replset.deleteOne({_id: oldId}) 关闭副本集节点。
注意
Ops Manager
If you are using Ops Manager, you must stop Ops Manager from managing the replica set before you shut down the replica set member. For more information on this procedure, see Remove a Process from Ops Management
在其原始端口启动副本集成员。
如果使用配置文件,确保将
replication.replSetName设置为新的副本集名称。