I am able to connect to Mongo DB through Compass and code on my local system but when I try to deploy the code to an Ubuntu server, it is giving me this error:
ERROR IN CONNECTING TO DATABASE Error: querySrv ENOTFOUND _mongodb._tcp.tha.ovfl8.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (internal/dns/promises.js:172:17) {
errno: undefined,
code: ‘ENOTFOUND’,
syscall: ‘querySrv’,
hostname: ‘_mongodb._tcp.tha.ovfl8.mongodb.net’
}
I am quite sure that this is a problem with Ubuntu because I’ve tried running it on Windows and Mac both and it was working fine.
I’ve whitelisted the IP and my Mongo DB is not dormant.
Can anybody please help? I’m quite new to Mongo DB atlas
Before anything else, can you try to connect from this Ubuntu server to MongoDB Atlas using mongosh using the command line provided when you click “connect” in Atlas?
This will make sure that it’s not an issue related to network, VPN, firewalls, etc but currently my guess is that your Ubuntu server can’t connect to port 27017 for some internal security reasons.
Head back to the network settings of your cluster and set it to “allow access anywhere” and try again. If it still fails to connect it is DNS/Firewall/VPN settings of your Ubuntu server as @MaBeuLux88_xxx mentioned. Else, you are setting wrong IP address in your whitelist.
;QUESTION
tha.ovfl8.mongodb.net. IN ANY
;ANSWER
;AUTHORITY
mongodb.net. 900 IN SOA ns-761.awsdns-31.net. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 60
;ADDITIONAL
We see this error a lot and it is almost always related to the host environment. let me highlight them.
host has strict rules and must be set manually. try this and see if, at least, ports are open: curl http://portquiz.net:27017
the other thing is your host’s network is not set correctly. its DNS does not know how to resolve the address. (we lately had such a problem with replit.com containers). I am not a guru on Linux, so cannot point out where to look.
The port was already open.
If I am able to connect through MONGOSH, i should be able to connect via Node js code also. It is not a network issue, it is something else.
Could you please explain the meaning of this error message so that I can debug the issue on my own
ERROR IN CONNECTING TO DATABASE Error: querySrv ENOTFOUND _mongodb._tcp.thoughtsutra.ovfl8.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (internal/dns/promises.js:172:17) {
errno: undefined,
code: ‘ENOTFOUND’,
syscall: ‘querySrv’,
hostname: ‘_mongodb._tcp.thoughtsutra.ovfl8.mongodb.net’
}
another reason that comes to mind is that you are using an older driver version (which we keep forgetting to ask). What driver version are you trying to use?
there are two connection string versions: old mongodb:// and new mongodb+srv://. in the old format, you need to give the address of each cluster member. in the new one, only cluster address is given and it is resolved to member addresses with an SRV record resolver. old drivers do not understand this new string format and fail to resolve cluster addresses.
from the same location you get your connection string (connect with application) select the oldest nodejs driver version and use that mongodb:// connection string and report back so we would know if that is the issue.