Setup a 2 node mongodb replica set

Hi Team,

Can it possible to setup a 2 node mongodb cluster? with Automatic failover option?

please reply.


Technically, yes. Is it useful, no.

No. You need another node. This helps determine which host is unavailable in the case of a network partition, among other things.

The minimum recommended configuration for a replica set is a three member replica set with three data-bearing members: one primary and two secondary members. In some circumstances (such as you have a primary and a secondary but cost constraints prohibit adding another secondary), you may choose to include an arbiter. An arbiter participates in elections but does not hold data (i.e. does not provide data redundancy).


but in our requirements. we have only two nodes? can it possible in anyway to setup the nodes using only 2 nodes

This is not how it works. If you want replication and availability as provided by replica sets then you need 3 nodes. At a minimum you need 2 data nodes and an arbiter.

Whoever is responsible for your requirements needs to read up on MongoDB replication.


Yes , Pankaj ,

You can setup 2 Node Mongodb Cluster with the help of 1 Arbiter node. In this setup you will have 2 Data bearing Node and 1 Non-data bearing node(Arbiter). But this setup act as automatic fail-over always.

Node 1 : Mongod1 (Primary)
Node 2 : Mongod2(Seconadry) , Arbiter


Node 1 : Mongod1(Primary) . Arbiter
Node2 : Mongod2(Seconadry)

But this setup will not fall in automatic fail-over category always.

You can take benefit from you existing any application server and deploy Arbiter node to achieve automatic fail-over.

Node 1 : Mongod1 (Primary)
Node 2 : Mongod2(Seconadry)
AppSer : Arbiter

but ARBITER is also a node right ? arbiter is a 3rd node. but i have only two node setup in two different virtual machine

An arbiter is a lightweight node that doesn’t hold any data. This node is used in voting to break ties.

An even number of nodes is not recommended in a production environment. In your scenario of using two data bearing nodes (a primary and a secondary), should one of those instances stop working, you will no longer be able to write to your database as MongoDB needs a majority (the floor of 50% + 1 nodes from the replica set) to be participating (connectable from the other nodes). This is why @satvant_singh was recommending an arbiter on your application server, as long as that’s not on one of the servers hosting your database instances.

Yes , @Doug_Duncan Explain very well ! Arbiter just help during election and only exchange credentials from other node, and No Data.

in my case i am setting the mongo server on the vm only. how can we set up Arbiter on the aplication server ?

You would add MongoDB to your application server as you did for the primary and secondary instances that are running in the VMs. Once the mongod process is running on the application server you would connect to the primary mongod instance via a mongo shell and run rs.addArb(...). You can learn how to use the rs.addArb() method in the documentation.

Yes, You have setup on VM machine , to complete the quorum of 3 nodes add another node(Arbiter) on App server if you can’t afford new VM. Process is already clarified by @Doug_Duncan. Still you need help we are here to help you.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.