Navigation

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.

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.

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.

  3. Connect to the replica set member.

  4. Update the replica set name in the local database with the following commands:

    /* 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.