Initiating a replica set involves connecting to one of the member servers in the replica using the mongo shell. If database security has been activated, be sure to log in as a user with the appropriate cluster administration role. The key command used to initiate the replica set is rs.initiate(). The generic syntax is as follows:
rs.initiate( <DOCUMENT> );
The rs.initiate() shell method is actually a wrapper for the replSetInitiate database command. If preferred, you can directly access this command using the following syntax from the shell (or from programming application code):
db.runComand( replSetInitiate : <DOCUMENT> )
The replica set configuration document supplied as an argument is in JSON format and can contain any of the following replica set configuration fields. We will first summarize the main replica set configuration fields.