Skip to content

Commit 37c547f

Browse files
author
Sam Kleinman
committed
merge: DOCS-268
2 parents 2eb1805 + 527a3d0 commit 37c547f

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

source/administration/replica-sets.txt

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -129,42 +129,24 @@ directly.
129129
Replacing a Member
130130
~~~~~~~~~~~~~~~~~~
131131

132-
There are two processes for replacing a member of a :term:`replica set`:
132+
Use this procedure to replace a member of a replica set when the host
133+
name has changed. This procedure preserves all existing configuration
134+
for a member, except its hostname/location.
133135

134-
#. Remove and then re-add a member using the following procedure in
135-
the :program:`mongo` shell:
136+
Replacing a member is useful if you have an existing configuration
137+
and only want to change the hostname of a member rather than completely
138+
remove all configurations related to the existing/previous set member.
136139

137-
.. code-block:: javascript
140+
Use :method:`rs.reconfig()` to change the value of the
141+
:data:`members[n].host` field to reflect the new hostname or port
142+
number. :method:`rs.reconfig()` will not change the value of :data:`members[n]._id`.
138143

139-
rs.remove("mongo2.example.net:27018")
140-
rs.add({host: "mongo2.example.net:27019", priority: 0, hidden: true})
141144

142-
.. note::
143-
144-
The set member tracks its own replica set member ``_id``,
145-
which can cause conflicts when trying to re-add a previous member.
146-
147-
To resolve this issue, you can either restart the
148-
:program:`mongod` process on the member that you're re-adding, or
149-
you can make sure that you specify an ``_id`` in the :method:`rs.add()`
150-
document.
151-
152-
#. Use :method:`rs.reconfig()` to change the value of the
153-
:data:`members[n].host` field to reflect the new hostname or port
154-
number. In this case, the :data:`members[n]._id` field is not
155-
reused by the new member.
156-
157-
.. code-block:: javascript
158-
159-
cfg = rs.conf()
160-
cfg.members[0].host = "mongo2.example.net:27019"
161-
rs.reconfig(cfg)
145+
.. code-block:: javascript
162146

163-
The second method may be useful if you have an existing configuration
164-
and only want to change the hostname of a member rather than
165-
completely remove all configurations related to the existing/previous
166-
set member. The :data:`members[n]._id` field does not change as a
167-
result of this operation.
147+
cfg = rs.conf()
148+
cfg.members[0].host = "mongo2.example.net:27019"
149+
rs.reconfig(cfg)
168150

169151
.. warning::
170152

0 commit comments

Comments
 (0)