Skip to content

Commit 62ef4b7

Browse files
author
Sam Kleinman
committed
DOCS-351 adding replica set configuration examples
1 parent cb13548 commit 62ef4b7

File tree

1 file changed

+85
-31
lines changed

1 file changed

+85
-31
lines changed

source/reference/replica-configuration.txt

Lines changed: 85 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,10 @@ Configuration Variables
221221
Example Document
222222
----------------
223223

224-
The following document is a prototypical representation a MongoDB
225-
replica set configuration document. Square brackets (e.g. ``[`` and
224+
the following document is a prototypical representation a mongodb
225+
replica set configuration document. square brackets (e.g. ``[`` and
226226
``]``) enclose all optional fields.
227227

228-
229228
.. code-block:: javascript
230229

231230
{
@@ -234,53 +233,108 @@ replica set configuration document. Square brackets (e.g. ``[`` and
234233
{
235234
_id : <ordinal>,
236235
host : <hostname[:port]>
237-
[, arbiterOnly : true]
238-
[, buildIndexes : <bool>]
236+
[, arbiteronly : true]
237+
[, buildindexes : <bool>]
239238
[, hidden : true]
240239
[, priority: <priority>]
241-
[, tags: {loc1 : desc1, loc2 : desc2, ..., locN : descN}]
242-
[, slaveDelay : <n>]
240+
[, tags: {loc1 : desc1, loc2 : desc2, ..., locn : descn}]
241+
[, slavedelay : <n>]
243242
[, votes : <n>]
244243
}
245244
, ...
246245
],
247246
[settings: {
248-
[getLastErrorDefaults: <lasterrdefaults>]
249-
[, getLastErrorModes : <modes>]
247+
[getlasterrordefaults: <lasterrdefaults>]
248+
[, getlasterrormodes : <modes>]
250249
}]
251250
}
252251

253252
.. _replica-set-reconfiguration-usage:
254253

255-
Use
254+
use
256255
---
257256

258-
Most modifications of replica set configuration use the
259-
:program:`mongo` shell. Consider the following example:
257+
most modifications of replica set configuration use the
258+
:program:`mongo` shell. consider the following:
259+
260+
.. example::
261+
262+
Given the following replica set configuration:
263+
264+
.. code-block:: javascript
265+
266+
{
267+
"_id" : "rs0",
268+
"version" : 1,
269+
"members" : [
270+
{
271+
"_id" : 0,
272+
"host" : "mongodb0.example.net:27017",
273+
},
274+
{
275+
"_id" : 1,
276+
"host" : "mongodb1.example.net:27017"
277+
},
278+
{
279+
"_id" : 2,
280+
"host" : "mongodb2.example.net:27017",
281+
}
282+
]
283+
}
284+
285+
And the following reconfiguration operation:
286+
287+
.. code-block:: javascript
288+
289+
cfg = rs.conf()
290+
cfg.members[0].priority = 0.5
291+
cfg.members[1].priority = 2
292+
cfg.members[2].priority = 2
293+
rs.reconfig(cfg)
294+
295+
This operation begins by saving the current replica set
296+
configuration to the local variable ``cfg`` using the
297+
:func:`rs.conf()` method. Then it adds priority values to the
298+
:term:`document` where the :data:`members[n]._id` field has a value
299+
of ``0``, ``1``, or ``2``. Finally, it calls the
300+
:func:`rs.reconfig()` method with the argument of ``cfg`` to
301+
initialize this new configuration. The replica set configuration
302+
after this operation will resemble the following:
303+
304+
.. code-block:: javascript
305+
306+
{
307+
"_id" : "rs0",
308+
"version" : 1,
309+
"members" : [
310+
{
311+
"_id" : 0,
312+
"host" : "mongodb0.example.net:27017",
313+
"priority" : 0.5
314+
},
315+
{
316+
"_id" : 1,
317+
"host" : "mongodb1.example.net:27017"
318+
"priority" : 2
319+
},
320+
{
321+
"_id" : 2,
322+
"host" : "mongodb2.example.net:27017",
323+
"priority" : 1
324+
}
325+
]
326+
}
260327

261-
.. code-block:: javascript
262328

263-
cfg = rs.conf()
264-
cfg.members[0].priority = 0.5
265-
cfg.members[1].priority = 2
266-
cfg.members[2].priority = 2
267-
rs.reconfig(cfg)
268-
269-
This operation begins by saving the current replica set configuration
270-
to the local variable ``cfg`` using the :func:`rs.conf()`
271-
method. Then it adds priority values to the :term:`document`
272-
where the :data:`members[n]._id` field has a value of ``0``, ``1``, or
273-
``2``. Finally, it calls the :func:`rs.reconfig()` method with the
274-
argument of ``cfg`` to initialize this new configuration.
275-
276-
Using this "dot notation," you can modify any existing setting or
277-
specify any of optional :ref:`replica set configuration variables
329+
Using the "dot notation" demonstrated in the above example, you can
330+
modify any existing setting or specify any of optional :ref:`replica
331+
set configuration variables
278332
<replica-set-configuration-variables>`. Until you run
279333
``rs.reconfig(cfg)`` at the shell, no changes will take effect. You
280334
can issue ``cfg = rs.conf()`` at any time before using
281-
:func:`rs.reconfig()` to undo your changes and start from the
282-
current configuration. If you issue ``cfg`` as an operation at any
283-
point, the :program:`mongo` shell at any point will output the complete
335+
:func:`rs.reconfig()` to undo your changes and start from the current
336+
configuration. If you issue ``cfg`` as an operation at any point, the
337+
:program:`mongo` shell at any point will output the complete
284338
:term:`document` with modifications for your review.
285339

286340
The :func:`rs.reconfig()` operation has a "force" option, to make it

0 commit comments

Comments
 (0)