13

It looks like I cannot connect to my free Mongo Atlas cluster anymore. Everything was working and I have data that was collected when I look at the MongoDB website so I have no idea why it stopped working and can no longer connect. My entire site won't load.

This is there error I was getting:

{ Error: querySrv ENODATA _mongodb._tcp.blog-cluster-0hb5z.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:197:19)
  errno: 'ENODATA',
  code: 'ENODATA',
  syscall: 'querySrv',                                                                  Blog/app.js:54:14
  hostname: '_mongodb._tcp.blog-cluster-0hb5z.mongodb.net' }
NasyaAS
  • 229
  • 1
  • 3
  • 8
  • I fixed this issue by upgrading the node version. It was throwing the same error with node version 10.15.0 and got fixed by upgrading it to 15.3.0 . – Rajat Dec 05 '20 at 02:23
  • I literally restarted my machine and everything went back to normal. I use windows and when I started it back up it ran through an update dialog so I suspect it something to do with that. – bloo May 15 '21 at 11:07

5 Answers5

22

For some reason the dns server did not return srv records, changing the dns server to one that returns those records fixed the problem. (I used https://use.opendns.com/ to fix the it)

copperi
  • 355
  • 4
  • 8
  • 2
    This should be the accepted answer. I travel a lot for work and about 5-10% of WIFI networks end up having this issue. Once I changed my DNS provider to 8.8.8.8 (Google) I was able to connect. https://developers.google.com/speed/public-dns/docs/using I'd imagine you could use CloudFlare or various other DNS Providers but I have not tested. – Brandon McAlees Dec 23 '19 at 18:18
  • This one works for me. Updated my wifi's DNS server and the error went away. Thanks! – jemgaleon Apr 19 '20 at 13:03
  • this is answer you need, thanks! – Naruto Mar 21 '23 at 07:53
12

I had the same problem working in a Starbucks went home and it connected right away try a different wifi connection.

williamvivas
  • 189
  • 2
  • 4
  • is there any other way around this issue ? – Juan Ricardo Aug 18 '19 at 21:42
  • 1
    Yup same. In a starbucks and it's not working. – flynn Nov 05 '19 at 20:36
  • 1
    At Starbucks? Not working? Use the Node.js 2.2.12 connection string. Answer here: https://stackoverflow.com/a/55639024/2055760. The mongodb Atlas UI provides an option for it. On Step 1, select the Node.js driver, then change the version from 3.0 to `2.2.12 or later` and they'll give you a connection string that works on Starbucks WiFi. – Lance Anderson Jan 13 '20 at 22:56
  • Starbucks still does not allow connection :( – adarian Feb 07 '20 at 21:59
  • It's happening to me right now in a Starbuck. I even added the Starbucks IP in the white list. It is a conspiracy of starbucks against developers. – Diesan Romero Feb 11 '20 at 18:01
  • It happened to me at Starbucks too. One quick solution is to connect to a VPN. – Hansel Mar 09 '20 at 21:17
2

For me, this issue was only happening in a Starbucks coffee, and was something random, OpenDNS didn't work for me nor Google DNS or any other tried, funny because works just fine at home. Previously I was using mongodb+srv string format to connect inside "uri" using Mongoid and Ruby with a mongoid.yml configuration file.

In order to fix this issue, make sure to follow the configuration described in this link https://docs.atlas.mongodb.com/driver-connection/ (Mongoid Example)

production:
  # Configure available database clients. (required)
  clients:
    # Defines the default client. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: 'myDatabaseName'

      # Provides the hosts the default client can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - mycluster0-shard-00-00.mongodb.net:27017
        - mycluster0-shard-00-01.mongodb.net:27017
        - mycluster0-shard-00-02.mongodb.net:27017
      options:
        # The name of the user for authentication.
        user: kay

        # The password of the user for authentication.
        password: myRealPassword

        # The database or source to authenticate the user against. If the database
        # specified above is not admin, admin MUST be specified here.
        auth_source: admin

        # All Atlas servers use SSL. (default: false)
        ssl: true
Juan Ricardo
  • 143
  • 8
2

In some cases, this happens when your IP address is not whitelisted in the MongoDB Atlas cluster. This is why it works with your IP address at home where you originally signed up your account, but doesn't work at a coffee shop WIFI or elsewhere.

So make sure your current IP address is added into your MongoDB cluster.

Plus Pingya
  • 171
  • 8
1

I had this problem come up when I tried to access my MongoDB Atlas at a coffee shop. It had been working perfect previously, but suddenly was giving me this exact error. I am not sure why, I cannot give you all the details, but what fixed it for me was going to my cluster and connecting with the standard connection string. I copied and pasted that longer connection string and after putting in my password and setting it up, it worked for me. Hope that helped.