rror: querySrv ECONNREFUSED _mongodb._tcp.cluster0.xk55obw.mongodb.net

Viewed 16

Im trying to connect the database in my nodejs project. I have created a mongo account and I have chosen Coonect your application to your cluster using MonngoDB's native drivers. So the code to connect with the database is like this:

db.js

const mongoose = require("mongoose");

const connectDB = async () => {
  const conn = await mongoose
    .connect(
      "mongodb+srv://username:<password>@cluster0.xk55obw.mongodb.net/?retryWrites=true&w=majority",
      {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      }
    )
    .then(() => {
      console.log("Database Connected");
    })
    .catch((err) => console.log(err));
};

module.exports = connectDB;

When I run the project in my terminal I get this error:

Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.xk55obw.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
  errno: undefined,
  code: 'ECONNREFUSED',
  syscall: 'querySrv',
  hostname: '_mongodb._tcp.cluster0.xk55obw.mongodb.net'
}

The username and password are correct, I have checked them.

How can I solve this error?

0 Answers
Related