- Reference >
mongoShell Methods >- Replication Methods >
- rs.initiate()
rs.initiate()¶
On this page
Description¶
-
rs.initiate(configuration)¶ Initiates a replica set. Optionally, the method can take an argument in the form of a document that holds the configuration of a replica set.
The
rs.initiate()method has the following parameter:Parameter Type Description configurationdocument Optional. A document that specifies configuration for the new replica set. If a configuration is not specified, MongoDB uses a default replica set configuration. The
rs.initiate()method provides a wrapper around thereplSetInitiatecommand.
Replica Set Configuration¶
See Replica Set Configuration Document Example for details of replica set configuration document.
Example¶
The following operation initiates a new replica set with three members.
The three mongod instances must have started with the
--replSet command line option, or
replication.replSetName if using a configuration file, set
to myReplSet:
Connect to one of the mongod instances and run
rs.initiate().
Note
Run the method on only one of the mongod instances.
For details on replica set configuration, see Replica Set Configuration Fields.
For details on deploying a replica set, see Deploy a Replica Set.
See also