skip to Main Content

I’ve created a cluster on MongoDB Atlas and have successfully connected to it using Compass and also using Node running locally.
When I try to run the same code on my CentOS machine i get an ECONNREFUSEDerror. Here is my Node code

const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://myuser:[email protected]/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
  const collection = client.db("test").collection("devices");
  console.log("ERROR: " + err);

  client.close();
});

myuser and mypass are replaced by my actual username and password here.

I’ve opened up server’s firewall for ports 27015, 27016 and 27017.
Atlas is set up to accept connections from any incoming IP.

I really can’t think of what might be causing it…

2

Answers


  1. I’m not 100% sure but my connection strings are usually like
    mongodb://user:[email protected]:27017/db_name

    Login or Signup to reply.
  2. I’ve figured it out. It ended up being the cPanel Firewall, even though I’ve opened the ports through firewall-cmd, my cPanel was still bypassing that configuration with its own firewall.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search