@@ -129,42 +129,24 @@ directly.
129
129
Replacing a Member
130
130
~~~~~~~~~~~~~~~~~~
131
131
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.
133
135
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.
136
139
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`.
138
143
139
- rs.remove("mongo2.example.net:27018")
140
- rs.add({host: "mongo2.example.net:27019", priority: 0, hidden: true})
141
144
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
162
146
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)
168
150
169
151
.. warning::
170
152
0 commit comments