Getting Error, "queryServ ENOTFOUND" on Ubuntu

Hi!

I have been working with Mongo Atlas and connecting to it fine from my local MacBook pro laptop (using the node.js mongodb library).

However, when I try to connect to the database from my remote Ubuntu machine I am never able to connect. :cry:

Here is the error message:

Mongo error:  Error: querySrv ENOTFOUND _mongodb._tcp.cluster0-shard-00-01-xxxxx.mongodb.net
[0]     at QueryReqWrap.onresolve [as oncomplete] (dns.js:206:19) {
[0]   errno: 'ENOTFOUND',
[0]   code: 'ENOTFOUND',
[0]   syscall: 'querySrv',
[0]   hostname: '_mongodb._tcp.cluster0-shard-00-01-xahr1.mongodb.net'
[0] }

Anyone else having this issue where they are unable to connect to MongoDB from an Ubuntu server? My connection string looks like this:

mongodb+srv://AdminUser:password@cluster0-shard-00-01-xxxxx.mongodb.net/test?retryWrites=true&w=majority

Thanks!

1 Like

Hi @Jim_Lynch have you verified that the IP address of your Ubuntu machine has been whitelisted in Atlas?

1 Like

I am surprised that your SRV connection string has the following format:

In SRV strings the shard information is usually not present. I would try with

mongodb+srv://AdminUser:password@cluster0-xahr1.mongodb.net

The following should work at as DNS has the following information for your cluster

;; ANSWER SECTION:
_mongodb._tcp.cluster0-xahr1.mongodb.net. 59 IN SRV 0 0 27017 cluster0-shard-00-00-xahr1.mongodb.net.
_mongodb._tcp.cluster0-xahr1.mongodb.net. 59 IN SRV 0 0 27017 cluster0-shard-00-01-xahr1.mongodb.net.
_mongodb._tcp.cluster0-xahr1.mongodb.net. 59 IN SRV 0 0 27017 cluster0-shard-00-02-xahr1.mongodb.net.
1 Like

Thanks @steevej. I had found a random comment on stack overflow that trying to connect to a shard instead of the primary might work, but sadly it didn’t.

Any other ideas for something I can try? :thinking:

Thanks @Doug_Duncan, but I had already added the Ubuntu machine’s IP to the whitelist.

@Jim_Lynch Did you try as he suggested?
mongodb+srv://AdminUser:password@cluster0-xahr1.mongodb.net

Is there a difference in driver version between your host and the ubuntu host ?

Copy the connection string from the clusters connect button on cloud.mongodb.com . If you need the older style then select an older version of the driver for the correct string.

You can always connect with a shard URI in your case it would be

mongodb://AdminUser:password@cluster0-shard-00-00-xahr1.mongodb.net:27017,cluster0-shard-00-01-xahr1.mongodb.net:27017,cluster0-shard-00-02-xahr1.mongodb.net:27017/?authSource=admin&replicaSet=Cluster0-shard-0