Running `mongo` produces `Operation timed out` when using `brew services`

I’m using brew services to launch mongodb-community on my M1 Mac. However, I’m getting an error Operation timed out when trying to run mongo or connect to it on a different machine.

According to brew services ls it is started, and doesn’t look to have any errors.

When running mongod --config /opt/homebrew/etc/mongod.conf and trying to connect again, it works fine.

When looking at the Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist file everything looks correct:


This problem started to happen after I tried to copy the data folder to an external hard drive.

For reference my /opt/homebrew/etc/mongod.conf file looks like:

  destination: file
  path: /opt/homebrew/var/log/mongodb/mongo.log
  logAppend: true
  dbPath: /Volumes/Drive13_A/mongodb

Any ideas about why it would fail when using brew services but not mongod directly?


After restarting the computer brew services ls now reports an error. Looking at the logs I see this entry:

{"t":{"$date":"2021-10-09T16:18:50.166-06:00"},"s":"E",  "c":"CONTROL",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"DBPathInUse: Unable to create/open the lock file: /Volumes/Drive13_A/mongodb/mongod.lock (Operation not permitted). Ensure the user executing mongod is the owner of the lock file and has the appropriate permissions. Also make sure that another mongod instance is not already running on the /Volumes/Drive13_A/mongodb directory"}}

Appears to be permissions problem or a unclean/abrupt shutdown could not clear lock file or previous run would have been by a different user
Is another mongod running and using same directory path?
Check ownership of mongod.lock file.
Is it same as the owner of mongod?
One fix is to remove the file and start the service again
Before you do this first identify what is the cause of the error

This was resolved by giving mongod permissions in Security & Privacy.

System Preferences > Security & Privacy > Privacy > Files and Folders > mongod > Removable Volumes (should be checked)