Issues setting up MongoDB community 5.0 on MacOS "Error setting up listener"


I’m really new to MongoDB and I’m trying to connect to MongoDB locally in order to be able to develop a project but am coming into issues that I don’t really understand, so hoping for some help.

I am installing for Mac OS and followed the instructions on

I ran brew services start mongodb-community@5.0 and then ran brew services list and I have the following error:

“mongodb-community error 12288 root ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist”

Looking in the log file I can see the error:

{"t":{"$date":"2022-03-03T07:50:40.907-05:00"},"s":"E", "c":"CONTROL", "id":20568, "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Address already in use"}}}

Let me know if you need anymore information. This is my first time setting up something like this so I am a bit out of my depth.


To clarify, I’ve also run lsof -iTCP -sTCP:LISTEN and I don’t think there are any ports using Mongo

After talking through with a colleague, I managed to solve the problem. Sharing here in case someone has a similar issue.

Although I couldn’t see mongod in the above command I ran sudo lsof -iTCP -sTCP:LISTEN -n -P and then killed the mongod port kill 22311

After that I got a different error:

{"t":{"$date":"2022-03-03T08:19:38.033-05:00"},"s":"E", "c":"CONTROL", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory

So I created a folder with a path ~/data/db and then restarted mongod
sudo mongod --dbpath=Documents/Code/mongodb/data/db

The connection is now working.

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