Docs Menu
Docs Home
/
MongoDB Manual
/ /

Rename a Replica Set

On this page

  • Prerequisites
  • Procedure

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.

  • 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.

1

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

Perform the following steps for each replica set member:

  1. Start the replica set member on a different port without the --replSet option.

  2. Update the replica set name.

  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.insertOne(doc)
    db.getSiblingDB("local").system.replset.deleteOne({_id: oldId})
  5. Shut down the replica set member.

    Note

    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

  6. Start the replica set member on its original port.

Back

Configure a Secondary's Sync Target