0

I have been trying to connect to Atlas using the university.mongodb.com connection string:

mongodb+srv://m001-student:m001-mongodb-basics@cluster0-jxeqq.mongodb.net/test

But the compass GUI gives the following error:

queryTxt ETIMEOUT cluster-0-jxeqq.mongodb.net

I created my own cluster and tried again. But unfortunately, the same error showed up. I tried to write a JavaSript code as (the angular placeholders had the actual values in them):

const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://<user>:<password>@cluster0.amffz.gcp.mongodb.net/<dbname>?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
    if (err) return console.log(err);
  const collection = client.db("test").collection("collection-1");
  client.close();
});

...which gave me this error:

Error: queryTxt ETIMEOUT cluster0.amffz.gcp.mongodb.net
  at QueryReqWrap.onresolve [as oncomplete] (dns.js:202:19) {
  errno: undefined,
  code: 'ETIMEOUT',
  syscall: 'queryTxt',
  hostname: 'cluster0.amffz.gcp.mongodb.net'
}

In Atlas, I enabled the Network Access in the Security option to : 0.0.0.0/0

I disabled my firewall just to be sure that the connection is not being blocked:

sudo ufw disable

But nothing seems to work.

Any help?

[Edit]

System Config: Ubuntu 20.04 LTS

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
nwillo
  • 1,204
  • 9
  • 9
  • 1
    Your system appears to have broken DNS resolution. You can try the non-SRV URI that is also available in atlas. – D. SM Jun 22 '20 at 19:06
  • Hello. Thanks for your response. I tried with the non-SRV URI format. It gives me this error -> MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. I have already added my IP address in the Whitelist IP in Atlas along with 0.0.0.0/0. Why is this happening? – nwillo Jun 23 '20 at 04:34
  • Well, I figured it out. As you said, I have issues with my machine. I deployed the app on Google Cloud and it's working. Thank you for your time :) – nwillo Jun 23 '20 at 05:23

1 Answers1

0

I figured out that the machine which I was using had some problem with the connectivity.

I figured out the way to solve this. I uninstalled MongoDB. It seemed like it had some configuration issues. I removed mongodb and mongoose npm packages as well. Re-installed everything. And viola, it got connected!

Dharman
  • 30,962
  • 25
  • 85
  • 135
nwillo
  • 1,204
  • 9
  • 9