0

I am trying to connect to my database on MongoDB Atlas using mongoose. But every time it's giving me the following error:

(node:2327) UnhandledPromiseRejectionWarning: Error: queryTxt ETIMEOUT cluster0-abjwg.gcp.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:206:19)
(node:2327) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2327) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I have tried whitelisting the IP. Also, the same code is working fine on another machine but not on my machine.

The code is:

const express = require('express');
const mongoose = require('mongoose');

require('dotenv').config();

const app = express();
const port = process.env.PORT || 5000;

// Connecting to MongoDB
const uri = process.env.ATLAS_URI;
mongoose.connect(uri, {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true});
const connection = mongoose.connection;
connection.once('open', () => {
    console.log('Connection established');
})

app.use(express.json());

app.listen(port, () => {
    console.log(`Here we go on port: ${port}`);
});

It is supposed to give output:

Here we go on port: 5000
Connection established

But I'm getting the only the first output and the error.

2 Answers 2

1

DNS resolution for TXT records appears to be broken on your machine. You can use the legacy URI (the one without srv) to connect instead.

Sign up to request clarification or add additional context in comments.

3 Comments

Please elaborate. Or suggest me some tutorial or blog to do the same.
I don't know why it's broken but it seems like a common issue. Maybe something to do with systemd.
I changed my DNS to Google's DNS. Now it's working.
0

My Internet Service Provider was blocking the connection. I changed my DNS to Google's Public DNS and the error was no more. I followed the link below to change my DNS.
https://developers.google.com/speed/public-dns/docs/using

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.