How to Fix mongonetworkerror: connect econnrefused

The mongonetworkerror: connect econnrefused error occurs when a problem is connecting to a MongoDB server running on the localhost ( on port 27017. The “ECONNREFUSED” means that the server actively refused the connection.


  1. There might be a possibility that the MongoDB server is not running.
  2. You need to check the firewall because sometimes it blocks the connection.
  3. For any reason, the MongoDB service is down.

A MongoNetworkError occurs when a client cannot connect to a MongoDB server.

How to Fix mongonetworkerror: connect econnrefused

Follow the below steps to fix the “mongonetworkerror: connect econnrefused” error.

Checking that the MongoDB server is running

Make sure the MongoDB service runs on the machine where the error is generated.

You can check the service status by running the following commands.

  1. service mongod status: It displays the status of MongodB service.
  2. systemctl status mongod: showsays the same status as the MongoDB service.

Check the MongoDB configuration

You must verify that the MongoDB server is configured to listen on the correct IP address and port.

The default IP address is, and the default port is 27017.

Check the firewall

Ensure that the firewall on the MongoDB machine is not blocking connections on the MongoDB port.

You can check the status of the firewall by running the command sudo ufw status or systemctl status firewalld depending on your OS.

Check the connectivity

You must check that the machine where the error is generated can connect to the machine running MongoDB.

To check connectivity, you can use the ping command.

Check the MongoDB logs

Check the MongoDB logs for any additional information about the error.

The logs are located in the /var/log/mongodb or C:\Program Files\MongoDB\Server\4.4\log folder if you are a windows user.

Check the Driver version and configurations

Ensure that you are using the correct version of the MongoDB driver and that it is configured correctly.

Restart the service

If all the above steps are not working, you can try restarting the MongoDB service.

After checkout all these solutions, I hope one solution might work for you, and you can resolve the mongonetworkerror.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.