I have a MongoDB Replica Set on the cloud service. For security reason, the replica set is available to the cloud's internal network.
I followed that cloud service's guide and setup a proxy to each member of the replica set, on the proxy-server:
0.0.0.0:27017 -> member1-private-ip:27107
0.0.0.0:27018 -> member2-private-ip:27107
0.0.0.0:27019 -> member3-private-ip:27017
...
I'm able to connect to every member of the replica set from a public network in standalone mode:
mongoUri = new MongoClientURI("mongodb://usr:pwd@proxy-server-public-ip:27017/db") ;
client = MongoClient(mongoUri);
But when I try connect it in replica set mode:
mongoUri = new MongoClientURI("mongodb://usr:pwd@proxy-server-public-ip:27017,proxy-server-public-ip:27018,proxy-server-public-ip:27019/db?replicaSet=replcaSetName");
client = MongoClient(mongoUri);
I would fail with connection error, since the replicat set tell the driver to use each member's internal addresses (inaccessible from public network).
p.s: I could connect to the replica set in replica set mode on the proxy server.
How can I connect to my replica set behind a proxy server?
Update: I use public address of the proxy server while connecting.