Please Help me to solve the following error

// code
import mongoose from “mongoose”;
import dotenv from “dotenv”;


const url = process.env.MONGODB_CONNECTION_URL || “”;
mongoose.set(“strictQuery”, true);

const Connection = async () => {
try {
await mongoose.connect(url);
console.log(“Juice Bar Database is Running”);
} catch (error) {
console.log(“Error while connecting with DB”);

export default Connection;

The error connection refused typically occurs when the MongoDB server is not running or is not accessible at the URL specified in the connection string. Here are a few common causes:

  1. Incorrect Connection URL: Make sure the URL specified in the MONGODB_CONNECTION_URL environment variable is correct and reachable.
  2. MongoDB Server Not Running: Verify that the MongoDB server is running and accessible on the network. You can do this by using the mongo command in the terminal to connect to the database.
  3. Firewall Blocking the Connection: If the MongoDB server is running on a different machine, make sure the firewall on that machine is not blocking the connection. You can check the firewall rules and allow incoming connections on the MongoDB port (27017 by default).
  4. Network Configuration: If the MongoDB server and the client are on different networks, make sure that the network configuration allows connections between the two.

Try resolving these issues and see if the error persists. If the error continues, try updating the MongoDB driver version or checking the MongoDB logs for more information.

The error EREFUSED is not

So it is not about

the error would be a parse error if not formatted correctly or ENOTFOUND if formatted correctly but wrong.

as the

it is not about

It is also not about

It is clear that they are the URI specifies an Atlas cluster and the DNS information is correct as seen in

;ANSWER 60 IN TXT "authSource=admin&replicaSet=atlas-12a1mm-shard-0" 60 IN SRV 0 0 27017 60 IN SRV 0 0 27017 60 IN SRV 0 0 27017

What I suspect is that your Internet provider is using a deprecated DNS server that do not understand SRV records. Try setting your DNS resolver to use google’s

1 Like

Thanks alot for the clarification @steevej