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.
Best Answer
Check your firewall settings! If FW is open to outside, you can connect single node even with telnet. Of course check that you haven't configure mongod to listening only private IP network adapter.
If you are behind NATed gateway, there should be redirection from outside network to servers.