Initializing the replica set

The final step in the replica set's deployment is to open a mongo shell on only one of the servers in the replica set:

mongo --host <hostname>

You can then run the rs.initiate() command to perform the initialization. In the following example, we are initializing a replica set with three servers, ed, ted, and fred:

The rs.conf() and rs.status() commands can be used to confirm the status and health of the replica set. The full list of replica related commands can be found here: https://docs.mongodb.com/manual/reference/method/js-replication/#replication-methods.

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.