I have created a mongod replica cluster of 2 nodes , mongo1 and mongo2. to load balance I have added following rule in my haproxy

listen mongo_replica_cluster
        bind *:27017
        mode tcp
        balance roundrobin
        server mongo1 check inter 10s fall 3 rise 99999999
        server mongo2 check backup

but if the mongo1 goes down mongo2 becomes the primary but even if mongo1 comes up mongo2 remains primary but ha redirect all traffic to mongo1 which is slave now. I want to redirect all my traffic to only the primary node.


You don't use ha-proxy.

Every node what connects to this replica set should have mongodb://mongo1,mongo2/?replicaSet="yourRS" -connection string, what tells which nodes are on that replicaset.. String don't need always list all nodes, most of them is enough, because Application can "ask" where current primary is located.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.