/
replSetInitiate.txt
81 lines (55 loc) · 1.9 KB
/
replSetInitiate.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
===============
replSetInitiate
===============
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. dbcommand:: replSetInitiate
The :dbcommand:`replSetInitiate` command initializes a new replica set.
.. |command| replace:: ``replSetInitiate``
.. include:: /includes/fact-dbcommand.rst
.. note::
Run the command on only one of the :binary:`~bin.mongod` instances
for the replica set.
Use the following syntax:
.. code-block:: javascript
{ replSetInitiate : <config_document> }
The ``<config_document>`` is a :term:`document` that specifies
the replica set's configuration. For instance, here's a config document
for creating a simple 3-member replica set:
.. code-block:: javascript
{
_id : <setname>,
members : [
{_id : 0, host : <host0>},
{_id : 1, host : <host1>},
{_id : 2, host : <host2>},
]
}
IP Binding
----------
.. include:: /includes/fact-default-bind-ip.rst
Example
-------
Assign a config document to a variable and then to pass the document to
the :method:`rs.initiate()` helper:
.. code-block:: javascript
config = {
_id : "my_replica_set",
members : [
{_id : 0, host : "rs1.example.net:27017"},
{_id : 1, host : "rs2.example.net:27017"},
{_id : 2, host : "rs3.example.net", arbiterOnly: true},
]
}
rs.initiate(config)
Notice that omitting the port cause the host to use the default port
of 27017. Notice also that you can specify other options in the config
documents such as the ``arbiterOnly`` setting in this example.
.. slave-ok, admin-only
.. seealso:: :doc:`/reference/replica-configuration`,
:doc:`/administration/replica-set-deployment`, and :ref:`Replica Set
Reconfiguration <replica-set-reconfiguration-usage>`.