Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to connect on Mongodb Atlas port

I'm using an M0 GCP instance.

I can connect to the cluster using this string:

'mongodb+srv://my_user:my_pass@my_cluster-mbsnz.gcp.mongodb.net/db?retryWrites=true&w=majority'

I'm trying to use another client where I need to pass host and port, but I can't connect.

I tried telnet to the port 27017, but for some reason I'm not able to connect directly on the port.

curl http://my_cluster-mbsnz.gcp.mongodb.net:27017
curl: (7) Failed to connect to my_cluster-mbsnz.gcp.mongodb.net port 27017: Connection timed out

or

telnet my_cluster-mbsnz.gcp.mongodb.net 27017
Trying 185.82.212.199...
^C -> After a long time waiting

What might be wrong ?

like image 626
Kleyson Rios Avatar asked Nov 07 '22 15:11

Kleyson Rios


1 Answers

+srv urls use a DNS seed. On atlas, you can click into the cluster and you should be able to see the urls for your primary & your secondaries and use those urls to connect. You should also be able to use nslookup to get that info using part of that connection string, but it's probably simpler to just look up the urls through the UI.

https://docs.mongodb.com/manual/reference/connection-string/

In order to leverage the DNS seedlist, use a connection string prefix of mongodb+srv: rather than the standard mongodb:. The +srv indicates to the client that the hostname that follows corresponds to a DNS SRV record. The driver or mongo shell will then query the DNS for the record to determine which hosts are running the mongod instances.

like image 184
willis Avatar answered Nov 15 '22 05:11

willis