MongoServerSelectionError: connect ECONNREFUSED 13.xxx.xxx.x:27017, MongoDB Atlas

My app can not connect to MongoDB Atlas.

The Url:
mongodb+srv://myusername:password@1lalana-dev.inp06zb.mongodb.net/?retryWrites=true&w=majority

The error:

stderr:
npm WARN lifecycle The node binary used for scripts is /home/c1439621c/nodevenv/1lalana-server/14/bin/node but npm is using /opt/alt/alt-nodejs14/root/usr/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
MongoServerSelectionError: connect ECONNREFUSED 13.245.246.5:27017
    at Timeout._onTimeout (/home/c1439621c/nodevenv/1lalana-server/14/lib/node_modules/mongodb/lib/sdam/topology.js:312:38)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'ac-fwv9tmo-shard-00-01.inp06zb.mongodb.net:27017' => [ServerDescription],
      'ac-fwv9tmo-shard-00-02.inp06zb.mongodb.net:27017' => [ServerDescription],
      'ac-fwv9tmo-shard-00-00.inp06zb.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-109yxn-shard-0',
    commonWireVersion: 13,
    logicalSessionTimeoutMinutes: 30
  }
}

It work fine in local and in Heroku, but not in cPanel.
The IP Access List in MongoDB Atlas is already setup as Everywhere:
0.0.0.0/0 (includes your current IP address)

Hi @Tiavina_Mik,

It work fine in local and in Heroku, but not in cPanel.
The IP Access List in MongoDB Atlas is already setup as Everywhere:
0.0.0.0/0 (includes your current IP address)

I would recommend going over the following post’s discussion that also mentions cPanel connection attempts and the associated solutions involving port opening from the cPanel end. This is in addition to the fact you are able to connect to the cluster locally and from Heroku. The errors also mentioned in the stack overflow post that the OP posted also looks very similar to the one you have posted here.

If you’re still having issues connecting after attempting any of the suggested solution(s) on that post, please let us know what was attempted and any new errors.

Regards,
Jason

1 Like