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


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

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)



Hi @Stennie,

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


Works fine when changing the URL from localhost to 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:

  destination: file
  path: /opt/homebrew/var/log/mongodb/mongo.log
  logAppend: true
  dbPath: /opt/homebrew/var/mongodb
1 Like

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

try ping -n localhost to find out

@steevej shows up as 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?

hey@Stennie can you help me insetting up net,ipv613

Same here. MacOS running on M1 Pro, having localhost in the env file does not seem to work. I changed to and it works perfectly.

1 Like

I have the same problem with macOS Monterey running on Intel: I can connect with but not with localhost using MongoClient.
My localhost is well set to mongo localhost and mongo are both working.
mongod is running with “mongod --config /usr/local/etc/mongod.conf”

Note that this problem doesn’t happen to me directly when I start my computer, it only appears after some time of usage. I tried to change the rlimits with sudo launchctl limit maxfiles 2147483647 2147483647 but it didn’t appear to fix the issue.

as requested:

This thread already provides the solution. Read carefully. The most important post is stennie’s about IPv6.

1 Like

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