Step 6: Start each member of the replica set with the appropriate options. For each member, start a mongod and specify the key file and the name of the replica set. Also specify other parameters as needed for your deployment. For replication-specific parameters, see cli-mongod-replica-set required by your deployment. 

If your application connects to more than one replica set, each set should have a distinct name. Some drivers group replica set connections by replica set name. 

The following example specifies parameters through the --keyFile and --replSet command-line options: 

mongod --keyFile /mysecretdirectory/mongodb-keyfile --replSet "rs0" 

The following example specifies parameters through a configuration file: 

mongod --config $HOME/.mongodb/config 

In production deployments, you can configure a control script to manage this process. Control scripts are beyond the scope of this document. 

Step 7: Connect to the member of the replica set where you created the administrative users. Connect to the replica set member you started and authenticate as the siteRootAdmin user. From the mongo shell, use the following operation to authenticate: 

use admin db.auth("siteRootAdmin", "<password>"); 

Step 8: Initiate the replica set. Use rs.initiate() on the replica set member: 

rs.initiate() 

MongoDB initiates a set that consists of the current member and that uses the default replica set configuration. 

Step 9: Verify the initial replica set configuration. Use rs.conf() to display the replica set configuration object (page 652): 

rs.conf() 

The replica set configuration object resembles the following: 

{ "_id" : "rs0", "version" : 1, "members" : [ { "_id" : 1, "host" : "mongodb0.example.net:27017" } ] } 

Step 10: Add the remaining members to the replica set. Add the remaining members with the rs.add() method. 

The following example adds two members: 

rs.add("mongodb1.example.net") rs.add("mongodb2.example.net") 

When complete, you have a fully functional replica set. The new replica set will elect a primary . 

