Similiar to Rob Lopez / Craig Eddy's answer, here's what worked for me on macOS ventura 13, using [email protected] with homebrew:
I was getting the similar error after running brew services start mongodb-community
Name Status File
mongodb-community error 25600 ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
It always helps to check the logs using cat /usr/local/var/log/mongodb/mongo.log
In my case, looks like the last line states the problem "error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /usr/local/var/mongodb"
{"t":{"$date":"2023-06-03T14:30:42.768+08:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/usr/local/etc/mongod.conf","net":{"bindIp":"127.0.0.1, ::1","ipv6":true},"storage":{"dbPath":"/usr/local/var/mongodb"},"systemLog":{"destination":"file","logAppend":true,"path":"/usr/local/var/log/mongodb/mongo.log"}}}}
{"t":{"$date":"2023-06-03T14:30:42.769+08:00"},"s":"I", "c":"NETWORK", "id":5693100, "ctx":"initandlisten","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"acceptor TCP fast open","option":{"level":6,"name":261,"data":"00 04 00 00"},"error":{"what":"set_option: Invalid argument","message":"Invalid argument","category":"asio.system","value":22}}}
{"t":{"$date":"2023-06-03T14:30:42.769+08:00"},"s":"I", "c":"NETWORK", "id":5693100, "ctx":"initandlisten","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"acceptor TCP fast open","option":{"level":6,"name":261,"data":"00 04 00 00"},"error":{"what":"set_option: Invalid argument","message":"Invalid argument","category":"asio.system","value":22}}}
{"t":{"$date":"2023-06-03T14:30:42.770+08:00"},"s":"E", "c":"CONTROL", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /usr/local/var/mongodb"}}
Btw, I tried using sudo brew services start mongodb-community
and it worked but also got a warning that it's not recommended.
So I tried changing the permissions of /usr/local/var/mongodb
with this command and this solved the error:
sudo chown -R `id -un` /usr/local/var/mongodb
Just an addtl info:
- chown: command used to change the ownership of files and directories in Unix-like operating systems. The chown command allows you to specify a new owner for a given file or directory.
- -R: It is an option for the chown command that stands for "recursive." When used, it instructs chown to operate recursively, changing the ownership of all files and directories within the specified directory and its subdirectories.
- id -un: This is a command substitution enclosed within backticks. It executes the id -un command and substitutes its output as part of the overall command. The id -un command is used to retrieve the username of the current user. So, in this context, it fetches the username of the user executing the sudo command.
brew services list
, I get the following status.mongodb-community error root /Library/LaunchDaemons/homebrew.mxcl.mongodb-community.plist
. I am wondering this has some permission to add in the pList. But not sure how. Looking for help. β Rossini