How to do it...

  1. Start the first node in the replica set:
mongod --dbpath /data/server1/db --replSet MyReplicaSet
  1. Open a new Terminal window, connect to the replica set node using the MongoDB shell, and check the replica set's status:
rs.status(){  "info" : "run rs.initiate(...) if not yet done for the set",  "ok" : 0,  "errmsg" : "no replset config has been received",  "code" : 94,  "codeName" : "NotYetInitialized"}
  1. Initialize the replica set:
rs.initiate(){   "info2" : "no configuration specified. Using a default configuration for the set",   "me" : "vagrant-ubuntu-trusty-64:27017",   "ok" : 1}
  1. Check the replica set's status again:
rs.status(){ "set" : "MyReplicaSet", "date" : ISODate("2017-08-20T05:28:26.827Z"), "myState" : 1, "term" : NumberLong(1), ...

Get MongoDB Administrator’s 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.