read 4 min
11 / 11
Feb 7

Hi,

I am having trouble connecting to my MongoDB database from my hosting server at Heliohost.org. The server is running python 3.10.8 and all required dependencies have been installed. Port 27017 have also been opened for the primary and two secondary domain IPs i.e.

  1. radtech-shard-00-01.p4cyn.mongodb.net ( 18.138.205.196 )
  2. radtech-shard-00-00.p4cyn.mongodb.net ( 54.255.46.254 )
  3. radtech-shard-00-02.p4cyn.mongodb.net ( 52.74.75.34 )

My script managed to connect to the database from my local machine without problem but it failed to connect from the hosting server. My connection string used is:

mongodb+srv://user:password@radtech.p4cyn.mongodb.net/mydatabase?retryWrites=true&w=majority

I tried to get help from the server admins and the following are some of the feedbacks i got from them:

  1. The script you listed is trying to connect to radtech.p4cyn.mongodb.net which doesn’t exist, or at least there is no DNS for it…
  2. You can’t connect to a website that doesn’t return an A record. Either connect to it directly by IP address, ie: 18.138.205.196:27017, or come up with a new URL that actually exists…
  3. It doesn’t resolve for me either against any DNS server I’ve tried… A normal lookup (A) returns no value, and doing an ALL lookup returned a single TXT record… You need to either: Use an IP address directly, use a URL whose DNS zone actually has an A record in it, or contact the database host and ask them to fix their DNS zone…
  4. What we don’t understand is how this is working for you without an A record present, unless it’s doing something weird like only responding for requests in a certain part of the world (we are both in the USA, as is our server), or perhaps it’s using a SRV record instead?..
  5. You can use this tool https://dnschecker.org/#A/radtech.p4cyn.mongodb.net to check A records from 33 DNS servers all around the world. They all report that there is no A record for that domain…

Sorry as i’m pasting here the comments verbatim because i’m not that good at re-explaining this myself… i’m not really familiar with everything about DNS records, so could someone explain what is all this about? Why am i not able to connect to the database from my hosting server? what can/should my hosting server do to allow me to connect to MongoDB host ?

Thanks in advance…

read 4 min

please check your database server’s network access settings. it is possible you have strict IP access allowing only your local machine’s IP.

Unless you have configured Atlas to allow all IP addresses(which you shouldn’t do). You will need to add IP addresses of the servers that will be connecting to your Atlas cluster.

Pymongo only added dnspython as a dependency in 4.3.2 so prior to this version dnspython would have to be added to requirements.txt, this is one thing to check.

Atlas Documentation describes how to connect.

Server admins 3 and 4 got close. The mongodb+srv:// connection string is used to resolve both SRV records AND a txt record. You can read more at Connection String URI Format

So far, access from all IP addresses are allowed and dnspython has been installed.

Currently i have only requested for port 27017 to be opened… do i need to request for ports 27015 and 27016 to be opened too if i’m connecting to my cluster using the following connection string?

Welcome to the MongoDB Community @ra_rahim !

The hostnames you have provided all appear to be resolvable. If this was a newly created cluster, it is possible the hostnames have not propagated to your local DNS servers yet.

If possible I would try using different name servers, for example Google Public DNS.

The mongodb+srv connection string format uses SRV and TXT records to discover the cluster hostnames and connection settings. For more background, see MongoDB 3.6: Here to SRV you with easier replica set connections | MongoDB.

This is correct for any of the hostnames in your replica set. You need to use the Atlas hostnames (and ideally, the SRV url) to connect to your cluster.

Google Public DNS is generally a good starting point.

This suggestion incorrectly assumes that an SRV hostname will have an A record (it will not, as above).

One of my colleagues wrote a small tool to try to help checking Atlas connections. I suggest trying to run this from your host server environment: GitHub - pkdone/mongo-connection-check: Tool to check the connectivity to a remote MongoDB deployment, providing advice if connectivity is not achieved.

For an Atlas replica set, you will only need access to port 27017. Port 27016 is used for sharded clusters and port 27015 for the MongoDB Connector for BI. For a reference, please see Attempting to connect to an Atlas deployment from behind a firewall.

Regards,
Stennie

1 year later

Hi,

I tried to use both Google’s servers, neither could resolve a MongoDB address. They could not even resolve mongodb.net.
I have two different projects on cloud.mongodb.com. Both of them are set to accept connections from 0.0.0.0/0, but I could only connect to one, not the other.
How could I troubleshoot this?

Thanks

nslookup > server 8.8.8.8 Default server: 8.8.8.8 Address: 8.8.8.8#53 > radtech-shard-00-02.p4cyn.mongodb.net Server: 8.8.8.8 Address: 8.8.8.8#53 ** server can't find radtech-shard-00-02.p4cyn.mongodb.net: NXDOMAIN > sandbox-encryption.g7xx2.mongodb.net Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: *** Can't find sandbox-encryption.g7xx2.mongodb.net: No answer > mongodb.net Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: *** Can't find mongodb.net: No answer > server 8.8.4.4 Default server: 8.8.4.4 Address: 8.8.4.4#53 > mongodb.net Server: 8.8.4.4 Address: 8.8.4.4#53 Non-authoritative answer: *** Can't find mongodb.net: No answer >

Hi @Averell_Tran , there is room to learn more so I also learned new today after your comment.

Please refer to the answer in this post:
What happens(happened) to “mongodb.net”?

There you will see the dig command works and this sentence:

Atlas connections stings are SRV and TXT records and have to be queried specifically for those. The cluster servers are hosted on subdomains.

So, other than real connection or hardware problems, these connection issues we are discussing might actually have a root of mistreatment of these records.

Please check your tools, besides what Stennie added above, and let us know if your problem persists (maybe in another post).

12 months later

So what should i do if I am the only one in my org that cant connect?

Either your connection is not set correctly on your computer, or the ISP you use has a problem that prevents connection. Do you use a VPN or something like that?