O'Reilly logo

MongoDB Administrator’s Guide by Cyrus Dasadia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required