Econnrefused ::1:27017

Hi everyone, I have been having this issue since few days ago, when ever I start my node server I got this connect ECONNREFUSED ::1:27017, my mongo service is running; I have used several approach uninstalling and reinstalling agian momgo

Since you say service is up can you connect by mongo shell or by other tool like Compass to your mongo DB?

change localhost word to
127.0.0.1

Welcome to the MongoDB Community Forums @temitope_Adekeye !

Your connection refused message indicates an attempted connection via the IPv6 localhost alias ::1 (0:0:0:0:0:0:0:1).

By default mongod does not bind to IPv6 addresses: you would have to set net.ipv6 to true and add appropriate IPv6 addresses in net.bindIp.

If you are using the default mongod configuration you should be able to connect to localhost:27017 or the equivalent IPv4 address 127.0.0.1:27017.

If you are still having trouble connecting, please provide more information on your environment:

  • O/S version
  • MongoDB server version
  • How you are starting the MongoDB service
  • Tool & version you are using to test connecting to your MongoDB deployment (a matching version of the MongoDB Shell would be recommended)

Regards,
Stennie

Hi @Stennie,

I’m experiencing similar issues when trying to connect with MongoDB using mongoose.

mongoose.connect('mongodb://localhost:27017/MovieApp')

Works fine when changing the URL from localhost to 127.0.0.1. My operating system is a M1 based macOS. I’m running MongoDB as a (i.e. the mongod process) macOS Service**

My MongoDB confi file stored in “/opt/homebrew/etc” as follows:

systemLog:
  destination: file
  path: /opt/homebrew/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /opt/homebrew/var/mongodb
net:
  bindIp: 127.0.0.1

most likely localhost is not defined as 127.0.0.1 but to something else.

try ping -n localhost to find out

@steevej shows up as 127.0.0.1 for me

Then your error must be different from:

Please post a screenshot of what you are doing that shows the issue you are having.

Also share the output of the following commands:

ps -aef | grep [m]ongod
ss -tlnp | grep [2]7017

You may replace ss with netstat if have not the former.

@Armindaz, any followup on this?