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

22 Likes

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

10 Likes

Hi @Stennie_X,

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
3 Likes

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?

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 127.0.0.1 and it works perfectly.

2 Likes

I have the same problem with macOS Monterey running on Intel: I can connect with 127.0.0.1 but not with localhost using MongoClient.
My localhost is well set to 127.0.0.1. mongo localhost and mongo 127.0.0.1 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.