querySrv EREFUSED _mongodb._tcp.cluster0.tpvpc.mongodb.net

mongodb+srv://sam:<password>@cluster0.tpvpc.mongodb.net/test
After changing the password and the ‘test’ name to my password and database, while connecting to my database from compass it throws this error.
Not just compass, also when am trying to connect from my application with its corresponding connection string, am having the same error.
The error which keeps on coming is :
querySrv EREFUSED _mongodb._tcp.cluster0.tpvpc.mongodb.net

Thanks A2A :slight_smile:

Is your IP address correctly whitelisted?

3 Likes

I faced a similar issue while using MongoDB on Windows. What worked for me simply using a different internet connection. Like on switching to mobile hotspot it worked. Maybe there are some ISP level related

9 Likes

Hello,

I have been experience the same issue on my project but I managed to resolve by changing node version see below image.

Filename - Posts.js

const express = require("express");

const mongodb = require("mongodb");

const router = express.Router();

// Get Posts

router.get("/", async (req, res) => {

  try {

    const posts = await loadPostsCollection();

    res.send(await posts.find({}).toArray());

  } catch (e) {

    console.log(e);

  }

});

async function loadPostsCollection() {

  const client = await mongodb.MongoClient.connect(

    "mongodb://abc123:<password>@vue-expess-mongodb-shard-00-00.cc1pu.mongodb.net:27017,vue-expess-mongodb-shard-00-01.cc1pu.mongodb.net:27017,vue-expess-mongodb-shard-00-02.cc1pu.mongodb.net:27017/posts_db?ssl=true&replicaSet=atlas-zk87tt-shard-0&authSource=admin&retryWrites=true&w=majority",

    {

      useNewUrlParser: true,

      useUnifiedTopology: true,

    },

  );

  return client.db("posts_db").collection("posts");

}

module.exports = router;

Lemme know if this help!

Thanks

4 Likes

Thanks man. That was exactly the case with me. I was trying to connect with my collage wifi. But that gave an error.

But still didn’t got why my clg wifi restricts connecting to mongodb and what can I do for it?

Any help would be appreciated!

It’s possible that your college is blocking outbound connection towards port 27017. Please check with a 4G/5G connection maybe to see if this unlocks the situation. If this is the case, then you need to talk to the network admin.

Cheers,
Maxime.

Make sure to change the node version to 2.2.12 , this was my probleme
URI should look like this: mongodb://ayoubmongo:@ayoubkhatouri-shard-00-00.dopzz.mongodb.net:27017,ayoubkhatouri-shard-00-01.dopzz.mongodb.net:27017,ayoubkhatouri-shard-00-02.dopzz.mongodb.net:27017/?ssl=true&replicaSet=atlas-2ichwf-shard-0&authSource=admin&retryWrites=true&w=majority

1 Like

exactly and you can also change the network access to all IP addresses…in that way database can be accessed seamlessly

I faced a similar issue while using Mongoose then I again install mongoose with command npm i mongoose after that my issue was fixed.