Getting ECONNREFUSED and ReplicaSetNoPrimary errors

Hey @Ewan_Humbert - Firstly, welcome to the community :slight_smile:

So I have a free cluster on MongoDB Atlas for my node.js app. When I was developing the app, the connection to the database worked perfectly fine. Now I have deployed this app on a server and I get an error to connect to the remote db

Regarding the above, could you advise on the following:

  1. If the exact same code is being used (at least for the connection portion)
  2. When the connection initially worked, was the app hosted locally on your device? E.g. on your laptop and connection was working fine to Atlas
  3. When you get the errors connecting from the server where the app is deployed, have you tested connection from the initial development machine to compare if it was working during the same period?
  4. Further details regarding the environment where the app fails to connect. E.g. Is this now hosted on AWS?
  5. Driver version

I would also recommend you to please try performing the initial basic network connectivity tests and provide the output for the cluster you are having trouble connecting to (from the server where you have deployed your app):

  1. ping one of the hosts (prefereably the PRIMARY):
/// example
ping cluster0-shard-00-00.ze4xc.mongodb.net
  1. telnet to one of the hosts on port 27017 :
/// example
telnet cluster0-shard-00-00.ze4cx.mongodb.net 27017

Note: You can find the hostname in the metrics page of your cluster

Additionally, I would recommend to review the Troubleshoot Connection Issues documentation. You may also find the following blog post regarding tips for atlas connectivity useful too.

Regards,
Jason

5 Likes