Docs Menu

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

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.