@@ -295,24 +295,49 @@ Procedure
295
295
296
296
#. Edit the replica set configuration manually. The replica set
297
297
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.
302
299
303
- .. code-block:: javascript
300
+ |
304
301
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.
306
305
307
- cfg = db.system.replset.findOne( { "_id": "rs" } )
306
+ #. Switch to the ``local`` database.
308
307
309
- cfg.members[0].host = "mongodb0.example.net:27017"
308
+ .. code-block:: javascript
310
309
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
312
324
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"
314
328
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 } )
316
341
317
342
#. Stop the :binary:`~bin.mongod` process on the member.
318
343
@@ -325,7 +350,7 @@ Procedure
325
350
326
351
.. code-block:: bash
327
352
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)>
329
354
330
355
#. Connect to one of the :binary:`~bin.mongod` instances
331
356
using :binary:`~bin.mongosh`. For example:
@@ -342,7 +367,7 @@ Procedure
342
367
.. code-block:: javascript
343
368
344
369
{
345
- "_id" : "rs ",
370
+ "_id" : "rs0 ",
346
371
"version" : 4,
347
372
"members" : [
348
373
{
@@ -359,3 +384,4 @@ Procedure
359
384
}
360
385
]
361
386
}
387
+
0 commit comments