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 that 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.
When authentication is enabled, ensure that your user role has
find,insert, andremoveprivileges on thesystem.replsetcollection in each member'slocaldatabase.Tip
You can view the privileges for a role by issuing the
rolesInfocommand with theshowPrivilegesandshowBuiltinRolesfields both set totrue.
Procedure
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.
Rename the replica set.
Perform the following steps for each replica set member:
Start the replica set member on a different port without the
--replSetoption.Update the replica set name.
If using a configuration file, set
replication.replSetNameto the new name.If using the
mongodstartup command with the--replSetoption, note down the new replica set name for use in step f.
Connect to the replica set member.
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}) 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
Start the replica set member on its original port.
If using a configuration file, ensure that
replication.replSetNameis set to the new replica set name.If using the
mongodstartup command with the--replSetoption, pass the new name of the replica set to the--replSetoption.