翻译或纠错本页面
- Reference >
- Database Commands >
- Replication Commands >
- replSetInitiate
replSetInitiate¶
- replSetInitiate¶
The replSetInitiate command initializes a new replica set. Use the following syntax:
{ replSetInitiate : <config_document> }
The <config_document> is a document that specifies the replica set’s configuration. For instance, here’s a config document for creating a simple 3-member replica set:
{ _id : <setname>, members : [ {_id : 0, host : <host0>}, {_id : 1, host : <host1>}, {_id : 2, host : <host2>}, ] }
A typical way of running this command is to assign the config document to a variable and then to pass the document to the rs.initiate() helper:
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.