How to fix 'Error: querySrv EREFUSED' when connecting to MongoDB Atlas?

how to fix anything
how to fix phone
how to fix a zipper
how to fix a computer
how to fix broken things
how to fix stuff
how to fix keyboard

I am new to MongoDB 4.0.6 and tried to implement it into my website using Node/Express.js, but when I try to connect to mongodb+srv://${process.env.MONGOUSER}:${process.env.MONGOPASS} I'm getting this error:

{ Error: querySrv EREFUSED at QueryReqWrap.onresolve [as oncomplete] (dns.js:199:19) errno: 'EREFUSED', code: 'EREFUSED', syscall: 'querySrv', hostname: '' }

I've tried connecting to mongodb://localhost:27017/main, but this does seem work.

Here is the relevant code:

const mongoose = require('mongoose');

// Database
const uri = `mongodb+srv://${process.env.MONGOUSER}:${process.env.MONGOPASS}`;
const localURI = 'mongodb://localhost:27017/main';

var Project = require('./models/project');

mongoose.connect(uri, { useNewUrlParser: true });
const db = mongoose.connection;

db.once('open', () => console.log('Successfully connected to MongoDB'));
db.on('error', (e) => console.log(e));

// Routes
app.get('/', (req, res) => {
  Project.find({}, (e, projects) => {
    if (e) console.log(e);

    res.render('home.ejs', {
      projects: projects

So does anyone know how to fix this error and maybe explain what is happening here?

If you're encountering this error try to use the older connection string for Node.js 2.2.12 or later:


According to MongoDB, SRV is possibly not working due to Mongoose.

iFixit: The Free Repair Manual, Most things around us eventually break down and need to be fixed. Learn essential DIY repair Duration: 14:27 Posted: 27 Jul 2019 iFixit is a global community of people helping each other repair things. Let's fix the world, one device at a time. Troubleshoot with experts in the Answers forum—and build your own how-to guides to share with the world.

I had this same error when I was connecting with Node version 3.0 or later and I resolved it by downgrading to 2.2.12 or later version:

How to Fix ANYTHING, Timestamps 00:01 Slime cleaning trick 02:29 Coca-cola rust removal 02:55 Wall repair trick 03 Duration: 13:56 Posted: 21 Apr 2020 People Helping People Fix Stuff. Help is here! Learn how to do your own repairs and save money! This site is filled with articles written by skilled individuals. You will find step by step "How To", tips and tricks, and general guidance on fixing your stuff. Finding Solutions

  { useNewUrlParser: true, useUnifiedTopology: true },
  .catch(err => {
  .then(async client => {
    await MoviesDAO.injectDB(client)
    await UsersDAO.injectDB(client)
    await CommentsDAO.injectDB(client)
    app.listen(port, () => {
      console.log(`listening on port ${port}`)

Maybe can works with MongoClient( not Mongoose )

How To Repair Almost Everything, Bad back, blotchy skin, and a wobbly feeling in your gut? Our anatomies are feeling the strain of too long spent at home. Here's how: 1. Navigate to the Windows 10 Advanced Startup Options menu. On many laptops, hitting F11 as soon as you power on will 2. Click Startup Repair.

In our case antivirus/firewall is blocking,

Try to disable antivirus/firewall and check again. hope it will work.

What lockdown has done to our bodies – and how to fix it, The future of Gen Z's mental health: How to fix the 'unhappiest generation ever'. What will be the lasting effects of technology, social media and� How to Fix the Most Annoying Things in Windows 10. Windows 10 is great, but it has its issues, from unpredictable reboots to Cortana. Here's how to fix some of the more irritating quirks with

Pass option { useNewUrlParser: true, useUnifiedTopology: true } to the MongoClient constructor

const uri = "mongodb+srv://${process.env.MONGOUSER}:${process.env.MONGOPASS}"

mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true })
    .catch(error => console.log(error));

The future of Gen Z's mental health: How to fix the 'unhappiest , Click on the category image of the appliance that you have a problem with. Find your Repair guide. Make shore your watch the right tutorial. Then find the spare� If an Office application such as Word or Excel isn’t working correctly, sometimes restarting it will fix the problem. If that doesn’t work, you can try repairing it. When you’re done, you might need to restart your computer. Repair Office from the Control Panel. The steps to access the repair tool vary depending on your operating system.

How to Repair, Buy How to Fix (Just About) Everything: More Than 550 Step-By-Step Instructions for Everything from Fixing a Faucet to Removing Mystery Stains to Curing a by� Repair it yourself at home for free. This method is incredibly easy! Simply follow the step by step instructions in this video and you'll be able to replace any cracked screen (No matter how badly

How to Fix (Just About) Everything: More Than 550 Step-By-Step , STAT asked a number of public health experts for a single suggestion of how we get ourselves out of this mess. We got lots.

How to fix the Covid-19 dumpster fire in the U.S., Mac Service and Repair. Learn how to get your Mac desktop or Mac notebook fixed and how much it will cost. How do I get�

  • Hey Alex, have you whitelisted your IP with MongoAtlas?
  • Yes, I have whitelisted every IP using @VtoCorleone
  • Thanks for the answer, it worked for me as well. But I would love to know why isn't it working with 3.0?
  • When I asked the MongoDB staff, they said it might be because of Mongoose, but I don't know the specific answer.
  • This works although the "mongodb" package i am using from npm is at ^v3.5.7 which should be considered for "3.0 or later" connections. But the "3.0 or later" one works for my AWS EC2 instance just fine but not locally. local node -v -> 13.0.x AWS node -v -> 10.20.1
  • My god. I had to disable Win10 firewall for atlas connection to work...
  • haha... interesting. I'd scrub that from your stack post just so people can't try and guess a password for your credentials. Can you try connecting to the instance through the CLI? Just to test that your credentials and URL is correct?
  • Sorry for the late response. It does connect using the CLI, so I guess it must be something in my code.