MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017

Looks like you pasted both commands at once
Run them one by one
Second command is to check what mongods are running on your machine

1 Like

But mongod is not running. Or at least it is not listening on port 27017. @Andrea_Spiga, you have to keep mongod running. Why you app is logging Starting PostgreSQL 12 database server?

That’s postgreSQL listening to another port (5432). It starts automatically, it’s not part of the app per se. Also I tried killing the posgre process and it does not change.
Mongod is listening to 27017 as the log says no? Although I see it’s not listed

Yes the log said it was listening.

But the recent output of ss -tlnp indicates that no process is listening on 127.0.0.1:27017.

I see many possibilities:

  1. you terminated mongod after sharing the log and starting the app
  2. mongod is running on another machine

Yes I tried to find the 27017 with other options for the ss command and nothing, never appears.
Why does mongosh connect? To that port?

Ok by “another machine” do you mean anything else than another computer? Just for clarity.
The process is running, I don’t stop it, I restart it when I edit the config file or similar.

May be mongod was running when you connected.

May be you ran mongosh on another machine/vm/docker/pod/lxc where an instance of mongod is running.

Share a screenshot of the whole terminal that shows how you start mongod.

Also share a screenshot of the whole terminal that shows how you connect to the mongod you just started.

I’m getting lost here. I’ve already shared the screenshot with the service running. It is still running, as a windows service. I start the app with the command node app.js (shared previously).

This whole thing works fine on another computer (a mac), with the same configurations and same code, same terminal and same everything, obviously with the paths that apply to a macOS.

It is showing if any mongod is running.

But

We have not seen the output of this second command yet.

I have seen the log files but not

and we need

I added with mongosh from by previous post.

If the

it should work too. But since it does not, the something must be different, we just did not find it yet from what you shared. That is why we ask you to share more.

ECONNREFUSED, means one and only one thing. It means that there is not server listening at the given address and port. The output of ss -tlnp you shared confirms that no server is listening.