Unable to connect to serverless cluster (getaddrinfo ENOTFOUND)

I have a serverless cluster name moldypages-serverless.8vk4d.mongodb.net .

For a reason I can’t track down I can connect to it with Mongo Compass but not with any other program, including my own code. I wrapped mongoose’s source code that starts the connecting with more console.logs and this is what I see:

NEW MONGO CLIENT mongodb://dan:SOMEFAKEPASSWORD@moldypages-serverless.8vk4d.mongodb.net/moldypages {
  useUnifiedTopology: true,
  useNewUrlParser: true,
  promiseLibrary: [Function: Promise],
  driverInfo: { name: 'Mongoose', version: '5.13.7' }
CAUGHT ERROR getaddrinfo ENOTFOUND moldypages-serverless.8vk4d.mongodb.net
        const timeoutError = new MongoServerSelectionError(
MongoServerSelectionError: getaddrinfo ENOTFOUND moldypages-serverless.8vk4d.mongodb.net
    at Timeout._onTimeout (/home/dan/Documents/node/moldypages/node_modules/mongodb/lib/core/sdam/topology.js:437:30)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  reason: TopologyDescription {
    type: 'Single',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map(1) {
      'moldypages-serverless.8vk4d.mongodb.net:27017' => [ServerDescription]
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null

What I find equally strange is that I can’t query the A DNS entry for moldypages-serverless.8vk4d.mongodb.net:

drill A moldypages-serverless.8vk4d.mongodb.net 

;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 55697
;; flags: qr rd ra ; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 
;; moldypages-serverless.8vk4d.mongodb.net.	IN	A


mongodb.net.	60	IN	SOA	ns-761.awsdns-31.net. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 60


;; Query time: 14 msec
;; WHEN: Tue Aug 31 16:49:31 2021
;; MSG SIZE  rcvd: 138

Is there a different procedure for connecting to a serverless cluster that I’m not aware of?

When you DNS name is a cluster, like the one you have. You need to use SRV URI that that starts with mongodb+srv://….

The DNS entry for a cluster is a TXT address such as:

: steevej@linux ; dig TXT moldypages-serverless.8vk4d.mongodb.neT

; <<>> DiG 9.16.18 <<>> TXT moldypages-serverless.8vk4d.mongodb.neT
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35498
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

; EDNS: version: 0, flags:; udp: 512
;moldypages-serverless.8vk4d.mongodb.neT. IN TXT

moldypages-serverless.8vk4d.mongodb.neT. 60 IN TXT "authSource=admin&loadBalanced=true"

;; Query time: 26 msec
;; WHEN: Tue Aug 31 17:04:57 EDT 2021
;; MSG SIZE  rcvd: 115

more information at SRV record - Wikipedia

Added +srv to the URL string. Now I get this:

MongoParseError: Text record must only set `authSource` or `replicaSet`

I can DNS lookup the text record and it shows:

drill TXT moldypages-serverless.8vk4d.mongodb.net                                                                                        ~/Documents/node/moldypages  
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 21091
;; flags: qr rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 
;; moldypages-serverless.8vk4d.mongodb.net.	IN	TXT

moldypages-serverless.8vk4d.mongodb.net.	60	IN	TXT	"authSource=admin&loadBalanced=true"



;; Query time: 13 msec
;; WHEN: Tue Aug 31 23:28:28 2021
;; MSG SIZE  rcvd: 104

I’m still confused. This all started because my self-hosted database was too slow. I thought I could just slot in a new serverless instance from Atlas just by changing an environment variable… I didn’t realise I’d have to redo my whole project.

Try to create a free tier normal non server-less cluster.

You might need a more recent driver to be able to use server-less clusters.

1 Like

Welcome to the MongoDB Community Forums @Dan_Habot !

As @steevej mentioned, you need to upgrade your MongoDB driver if your current version is lower than the minimum supported driver version to connect to the Atlas Serverless preview. For Node.js you will need a 4.1.0 or newer driver version.

Mongoose 5.13.7 uses an older Node.js driver version (3.6.8) that does not have Atlas Serverless support. I expect that upgrading to Mongoose 6.0 or newer will resolve your connection issue.

There is no need to redo your project – you just have to meet the driver prerequisites.

I would note that Atlas Serverless is currently in a preview stage, so it is not recommended for production environments yet. The team would definitely appreciate any feedback and improvement suggestions.

Some more context on preview status via the Atlas Serverless FAQ:

Serverless instances will initially be available in preview, meaning they are not feature-complete or ready for production use.

During the preview phase, serverless instances will also be:

  • Not included in our uptime SLA
  • Limited or restricted in functionality
  • Available in select cloud regions

Thank you for trying Atlas!


1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.