Skip to content

DOCS-13922 describes procedure for renaming replica sets #5066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions source/faq/replica-sets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ times.
Can I rename a replica set?
---------------------------

No.
Yes, unsharded replica sets can be renamed. This procedure requires
downtime.

You can use the backup and restore procedure described in the
:doc:`/tutorial/restore-replica-set-from-backup` tutorial to create a
new replica set with the desired name. Downtime may be necessary in
order to ensure parity between the original replica set and the new one.
Before renaming a replica set, perform a full
:doc:`backup of your MongoDB deployment </core/backups>`.

.. include:: /includes/steps/rename-unsharded-replica-set.rst
49 changes: 49 additions & 0 deletions source/includes/steps-rename-unsharded-replica-set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
title: Shutdown Replica Set Members.
level: 4
ref: shutdown-replica-set
content: |
Follow the procedure in :ref:`Stop a Replica Set <stop-replica-set>`
to confirm that replica set members are
:ref:`shut down <terminate-mongod-processes>`.

---
title: Rename Replica Set Members.
level: 4
ref: rename-replica-set-members
content: |
Perform the following steps for each replica set member:

#. Update the replica set name in the
:ref:`configuration file <conf-file>` or adjust the
:binary:`~bin.mongod` startup command if not using a
configuration file.

#. Start the replica set member on a different port without the
:option:`--replSet <mongod --replSet>` option.

#. Connect to the replica set member.

#. Update the replica set name in the :ref:`local database
<replica-set-local-database>` with the following commands:

.. code-block:: javascript

/* 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})

#. :ref:`Shut down <terminate-mongod-processes>` the replica set
member.

#. Start the replica set member on its original port. If using a
configuration file, ensure the :setting:`replica set name
<replication.replSetName>` is set to the new name. Otherwise,
use the :binary:`~bin.mongod` startup command with the
:option:`--replSet <mongod --replSet>` option set to the new
replica set name.
...
3 changes: 1 addition & 2 deletions source/reference/replica-configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ Replica Set Configuration Fields

*Type*: string

The name of the replica set. Once set, you cannot change the
name of a replica set.
The name of the replica set.

:rsconf:`_id` *must* be identical to the
:setting:`replication.replSetName` or the value of `--replSet`
Expand Down
2 changes: 2 additions & 0 deletions source/tutorial/manage-mongodb-processes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ process, use the following command:
The resulting backtrace data is written to the :binary:`~bin.mongod`
logfile as configured with :option:`--logpath <mongod --logpath>`.

.. _stop-replica-set:

Stop a Replica Set
------------------

Expand Down