In MongoDB, nodes within replica sets perform elections to select a primary node. To ensure there is always a majority in the number of nodes, you can add an arbiter to the replica set. An arbiter is a mongod instance that does not store data but is only involved in voting during an election process. This can prove very useful, especially during network partitions that result in conflicting votes.
We can continue on from the previous recipe, in that all we need is a two node replica set.
- Create directories for the arbiter process:
mkdir -p /data/arbiter/db
- Start the arbiter process:
mongod --dbpath /data/arbiter/db --replSet MyReplicaSet --port 30000
- Open a new Terminal window and connect to the primary node:
mongo mongodb://192.168.200.200:27017
- Add the arbiter:
rs.addArb('192.168.200.200:30000')
- Check the members of the replica set:
rs.status()['member'] [ { "_id" : 0, "name" : "vagrant-ubuntu-trusty-64:27017", "health...