Kalyani Pullela
Kalyani Pullela

Reputation: 119

MongoDB replica set not connected in EC2 instance

I've taken mongodb instance and connected network load balancer and configured 3 instance replica set. When running as a single instance its working fine but while doing with the replica set, the 1st API hit is working fine but when I give the next hit it fails.

After continuous hits of multiple times it again gets the result. I've tried rs.secondaryOk() on the mongodb instance running on the replica set. While doing sometimes it works fine but after sometime it again fails with error of not primary secondary=false

Please let me know you thoughts on the same

Thanks in advance

Upvotes: 0

Views: 220

Answers (1)

R2D2
R2D2

Reputation: 10737

Connection URI to your replicaSet mongoDB must look something like that:

mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl

If you connect individually to every member via 3th party loadbalancer it will not work as expected ...

Upvotes: 1

Related Questions