How can I fix ECONNREFUSED error when the server is running

I want to access a mongodb database using mongosh. I’ve made sure using sudo systemctl status mongod that the server is active, but once I want to access it with mongosh, the following error pops up.

Current Mongosh Log ID:	62319666ca0a2501a0140a38
Connecting to:		mongodb://127.0.0.1:27017/db_name?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.2
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017

I’m willing to provide more information if needed, and thank you all for any assistance in advance!

ECONNREFUSED means no process is listening at the given address and port.

We need 3 things:

  1. the content of the configuration file /etc/mongod.conf
  2. the output of the command
    ps -aef | grep [m]ongod
  3. the output of the command
    ss -tlnp
2 Likes

It seems like the error has been fixed after I reinstall MongoDB and change to a different directory to store the data.

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.