Connect ECONNREFUSED after Mongod community 6.0 installation

Hi, I tried to install mongodb-community@6.0 via Brew, knowing that a previous version 5.0 was already installed. I followed the official procedure here https://www.mongodb.com/docs/v6.0/installation/.

I get the following message when starting the service:

Bootstrap failed: 5: Input/output error

Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501/Users/schub/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist` exited with 5.

I get this message when running mongosh

Current Mongosh Log ID: 638619ca4e5f303a7c13367b
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017

And here are the errors raised by launching mongod

{"t":{"$date":"2022-11-29T15:41:01.536+01:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2022-11-29T15:41:01.539+01:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2022-11-29T15:41:01.540+01:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"main","msg":"Multi threading initialized"}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":30902,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"MacJS.local"}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"CONTROL",  "id":23352,   "ctx":"initandlisten","msg":"Unable to resolve sysctl {sysctlName} (number) ","attr":{"sysctlName":"hw.cpufrequency"}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"CONTROL",  "id":23351,   "ctx":"initandlisten","msg":"{sysctlName} unavailable","attr":{"sysctlName":"machdep.cpu.features"}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.1","gitVersion":"32f0f9c88dc44a2c8073a5bd47cf779d4bfdee6b","modules":[],"allocator":"system","environment":{"distarch":"aarch64","target_arch":"aarch64"}}}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"22.1.0"}}}
{"t":{"$date":"2022-11-29T15:41:01.544+01:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2022-11-29T15:41:01.545+01:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
{"t":{"$date":"2022-11-29T15:41:01.545+01:00"},"s":"F",  "c":"ASSERT",   "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":1120}}
{"t":{"$date":"2022-11-29T15:41:01.545+01:00"},"s":"F",  "c":"ASSERT",   "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

And this after this commande

brew services restart mongodb/brew/mongodb-community

Name              Status      User  File
mongodb-community error  3584 schub ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

Tried everything I found on Google, StackOverflow and here, tried uninstalling and reinstalling but still getting the same errors.

thank you in advance for your help

I am not a Mac user, but I can interpret few of those errors.

When running locally, this error comes up because there is no service listening on that port. This means mongod failed to start. you need to inspect the cause, fix it, and then restart mongod again.

This error mostly arises because either there is an instance of server running on that port or an instance was not shutdown properly, hence the file is locked. The remaining part also tell that root access is needed.
First, check if the old version is still there and running. then stop it.
If there is no running server, even trying to run the server as root will fail. because the existence of this file causes mongod to think a server is already running. removing this lock file mostly solves the issue.

also, check if the new server is installed fine by this command: mongod --version.

Thank you for your reply.
The output of mongod --version is this:

db version v6.0.1
Build Info: {
     "version": "6.0.1",
     "gitVersion": "32f0f9c88dc44a2c8073a5bd47cf779d4bfdee6b",
     "modules": [],
     "allocator": "system",
     "environment": {
         "distarch": "aarch64",
         "target_arch": "aarch64"
     }
}

I used kill-port to kill the process on port 27017 and this is the result:

Could not kill process on port 27017. No process running on port.

And by the way I don’t know which file is locked and the file /tmp/mongodb-27017.sock does not exist on my mac.

this complicates things because that is in the last 3 lines of the logs. I don’t know how Mac’s root privileges work. did you try checking that file as root?

Another one is a few lines above that, but I don’t know what that means in a Mac.

thank you very much, but I’m new to macOS and I don’t know how to do this. I will find out how to do it.

Enter administrator commands in Terminal on Mac - Apple Support (IE)
sudo seems to do it.

try sudo rm /tmp/mongodb-27017.sock

also check this one and see if it is useful . macos - Failed to unlink socket file /tmp/mongodb-27017.sock errno:13 Permission denied - Stack Overflow

Thanks for these informations. I tried this command but nothing happens. I also tried StackOverflow suggestions but that doesn’t work either. And the files that are mentioned in the logs are no longer available.

I am sorry to hear that. I can interpret error messages as they are almost the same in all operating systems. I just can’t confirm what happens on macos.
I have found the following topic with pretty much the same problem. the difference I can see is how he tries to start the service. It might be related so check it out if you haven’t
HELP: Brew mongodb-community@5.0 error [MacOS] - Ops and Admin / Installation & Upgrades - MongoDB Developer Community Forums

it again has this socket file problem and solves it. check the commands they used.

If you still fail to have a solution, you may tag “Stennie” from that post for a look at it here. to tag someone, start typing “@” symbol and the name. I hope he has an idea.

The permission related issues occur if you had run mongod as root
So check permissions on dbpath & logpath folder
ls -lrt /tmp/mongod-27017.sock
If you have multiple versions you have to start brew service giving the version number but your command does not append version number
Also from logs i see it is using /data/db which is default dbpath location.On Macos access to root folders is removed.If this is causing issues you have to give different dirpath
Till your default mongod on port 27017 issue is resolved you can always spinup your own mongod on a different port,dbpath,logpath by giving some port like 28000 and your home directory
Ex:
Mongod --port 28000 --dbpath homedir --logpath homedir/mongod.log --fork

1 Like

Thank you for your answers but I still face the same errors. And Ramachandra_Tummala,

  • the file /tmp/mongodb-27017.sock does not exist on my mac.
  • I tried to launch with the version number, but I get the same message

@Stennie: do you have an idea to solve my problem?

Thank you in advance for your assistance