Wednesday, 27 August 2014

Setting up a MongoDB replica set

  • All nodes have to be started with this flag --replSet "clusterName"
  • In one of the nodes, execute the following commands
    $ mongo
    > rs.initiate()
    > rs.add("hostname1")
    > rs.add("hostname2")
    
  • This command will allow you to execute queries in a slave node
    > rs.slaveOk()
    
  • This command will show you the status of the cluster
    > rs.status()