I looked into answers but nothing works for me in mongo 2.6.11 cluster 'nms' (members nms01m and nms02) below. I want my current secondary nms01m to become primary, and now nms02 is primary instead of nms02 (after nms01m failure last night). I tried stopping nsm02, restarting nms01m , changing priority, rs.reconfig(cfg, {force : true}) but nothing helps. It is always a struggle for me
nms:SECONDARY> rs.conf()
{
"_id" : "nms",
"version" : 193970,
"members" : [
{
"_id" : 0,
"host" : "nms02:27017",
"priority" : 2
},
{
"_id" : 1,
"host" : "nms01m:27017"
}
]
}
Best Answer
A MongoDB replica set should have at least 3 members in order to help you achieve high availability.
The rule for MongoDB replica set failover (when a new member becomes a primary) is that the MAJORITY of the "surviving" nodes vote for it to become the new primary.
So let's think about this:
If for any reason you are not interested in investing in a 3rd server for your MongoDB replica set, you can consider using an arbiter. The arbiter can be a very small machine, and it requires minimum amounts of CPU and storage. But an arbiter votes in an election and it is counted as one of the nodes.
Look at this link in the MongoDB documentation: [https://docs.mongodb.org/v3.0/core/replication-introduction/#automatic-failover][1]
In a situation where you have 2 "regular" members of a MongoDB replica set, plus an arbiter, in case one of the members fails, the replica and the surviving node, will form a MAJORITY which is needed for the election of a new primary. [https://docs.mongodb.org/v3.0/core/replica-set-arbiter/][1]