Skip to content

Commit 9d9e9e2

Browse files
author
Dave
authored
DOCSP-20804 BACKPORT (#711)
1 parent a39799a commit 9d9e9e2

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

source/tutorial/change-hostnames-in-a-replica-set.txt

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,24 +295,49 @@ Procedure
295295

296296
#. Edit the replica set configuration manually. The replica set
297297
configuration is the only document in the ``system.replset``
298-
collection in the ``local`` database. Edit the replica set
299-
configuration with the new hostnames and correct ports for all
300-
the members of the replica set. Consider the following sequence of
301-
commands to change the hostnames in a three-member set:
298+
collection in the ``local`` database.
302299

303-
.. code-block:: javascript
300+
|
304301

305-
use local
302+
To change the hostnames, edit the replica set configuration to
303+
provide the new hostnames and ports for all members of the
304+
replica set.
306305

307-
cfg = db.system.replset.findOne( { "_id": "rs" } )
306+
#. Switch to the ``local`` database.
308307

309-
cfg.members[0].host = "mongodb0.example.net:27017"
308+
.. code-block:: javascript
310309

311-
cfg.members[1].host = "mongodb1.example.net:27017"
310+
use local
311+
312+
#. Create a JavaScript variable for the configuration document.
313+
Modify the value of the ``_id`` field to match your replica
314+
set.
315+
316+
.. code-block:: javascript
317+
318+
cfg = db.system.replset.findOne( { "_id": "rs0" } )
319+
320+
#. Provide new hostnames and ports for each member of the replica
321+
set. Modify the hostnames and ports to match your replica set.
322+
323+
.. code-block:: javascript
312324

313-
cfg.members[2].host = "mongodb2.example.net:27017"
325+
cfg.members[0].host = "mongodb0.example.net:27017"
326+
cfg.members[1].host = "mongodb1.example.net:27017"
327+
cfg.members[2].host = "mongodb2.example.net:27017"
314328

315-
db.system.replset.update( { "_id": "rs" } , cfg )
329+
#. Update the hostnames and ports in the ``system.replset``
330+
collection:
331+
332+
.. code-block:: javascript
333+
334+
db.system.replset.updateOne( { "_id": "rs0" }, { $set: cfg } )
335+
336+
#. Verify the changes:
337+
338+
.. code-block:: javascript
339+
340+
db.system.replset.find( {}, { "members.host": 1 } )
316341

317342
#. Stop the :binary:`~bin.mongod` process on the member.
318343

@@ -325,7 +350,7 @@ Procedure
325350

326351
.. code-block:: bash
327352

328-
mongod --dbpath /data/db1/ --port 27017 --replSet rs --bind_ip localhost,<hostname(s)|ip address(es)>
353+
mongod --dbpath /data/db1/ --port 27017 --replSet rs0 --bind_ip localhost,<hostname(s)|ip address(es)>
329354

330355
#. Connect to one of the :binary:`~bin.mongod` instances
331356
using :binary:`~bin.mongosh`. For example:
@@ -342,7 +367,7 @@ Procedure
342367
.. code-block:: javascript
343368

344369
{
345-
"_id" : "rs",
370+
"_id" : "rs0",
346371
"version" : 4,
347372
"members" : [
348373
{
@@ -359,3 +384,4 @@ Procedure
359384
}
360385
]
361386
}
387+

0 commit comments

Comments
 (0)