Rename a Replica Set重命名副本集

On this page本页内容

To rename a replica set, you must shut down all members of the replica set, then configure each member's local database with the new replica set name.要重命名副本集,必须关闭副本集的所有成员,然后使用新的副本集名称配置每个成员的local数据库。

This procedure requires downtime.此过程需要停机。

Prerequisites先决条件

  • Ensure your replica set is not sharded. 确保副本集未分片化。The renaming procedure is for unsharded replica sets only.重命名过程仅适用于未排序的副本集。
  • Before renaming a replica set, perform a full backup of your MongoDB deployment.重命名副本集之前,请执行MongoDB部署的完整备份

Procedure过程

1

Shut down replica set members.关闭副本集成员。

Follow the procedure in Stop a Replica Set to confirm that replica set members are shut down.按照停止副本集中的步骤确认副本集成员已关闭

Warning警告

This step requires downtime as all replica members will need to be shut down.此步骤需要停机,因为所有复制副本成员都需要关闭。

2

Rename the replica set.重命名副本集。

Perform the following steps for each replica set member:对每个副本集成员执行以下步骤:

  1. Update the replica set name.更新副本集名称。

  2. Start the replica set member on a different port without the --replSet option.在不使用--replSet选项的其他端口上启动副本集成员。
  3. Connect to the replica set member.连接到副本集成员。
  4. Update the replica set name in the local database with the following commands:使用以下命令更新local数据库中的副本集名称:

    /* 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.save(doc)
    db.getSiblingDB("local").system.replset.remove({_id: oldId})
  5. Shut down the replica set member.关闭复制集成员。
  6. Start the replica set member on its original port.在其原始端口上启动复制集成员。

←  Configure a Secondary's Sync TargetModify PSA Replica Set Safely →