I have configured a three-node replica set in MongoDB. I am able to connect to each server and replication is in sync. But when I'm trying to connect to them as a replica set from a public IP, I am getting an error:
No primary detected for set rs0
But I am able to connect to the replica set from private IPs.
mongo --host rs0/52.X.X.X:27017,52.X.X.X:27017,52.X.X.X:27017 -uroot -pabc123 --authenticationDatabase admin this public IP not able to connect mongo --host rs0/10.X.X.X:27017,10.X.X.X:27017,10.X.X.X:27017 -uroot -pabc123 --authenticationDatabase admin
With these private IPs we are able to connect to the replica set.