Search code examples
mongodbshardingreplicaset

MongoDB two member replica-set


I have a two member replica set (within a sharded cluster), with no arbiter. I know that the recommended design is to have three servers (or an odd number) but right now I have to stick with this design.

The problem is that when the primary is down, the secondary doesn't get elected as a temporary master (since the priority for both servers is 1 and I have no arbiter).

Is there any way to get that automatic failover (slave becomes primary -> primary back online -> default primary gets its previous state)?

Thank you!


Solution

  • You MUST have at least 3 members in the replicaset, having 2 members is worse than having just a single node (NEVER EVER DO THIS!!). Your problem is worst than you think, the main problem is that if your secondary goes down, your primary will demote itself to a secondary and also effectively go down because you have no more primary. I don't know why you 'have to stick with this configuration, but it can not be a solution.

    The solution to this is to create an arbiter, node, this is simply a lightweight member of the replicaset that has no actual data and is simply there to take part in the election for a new primary if one of the other members goes down.