Unable to connect to replica set via mongosh

I am able to connect to connect to each of my 3 node replica set individually in direct connection mode using

mongosh "mongodb://user:pass@34.93.99.32:27017/dbname"

But when I try connecting to the replicaset with

mongosh "mongodb://<ip1>:27017,<ip2>:27017,<ip3>:27017/?replicaSet=rs0"

it fails with error

MongoServerSelectionError: Server selection timed out after 30000 ms

Since I’m able to connect to the individual nodes separately I’m assuming it’s not a network issue.

All 3 nodes are on GCP VMs. I’ve already configured the firewalls. All VMs have public IPs.

Please share your rs.status().

@steevej Thanks for the interest, but I just solved a few hours back. Turns out I had given private IPs of the nodes when creating the replica set, but was trying to connect using the external IPs. I’ve reconfigured the replicaset with the external IPs and it’s working fine

1 Like