Solomon Egwuonwu
Solomon Egwuonwu

Reputation: 31

MongoDB on macOS: How do I resolve chown: data/db: No such file or directory

I installed MongoDB via Homebrew and created the /data/db directory.

When I run sudo chown -R id -un /data/db. I get this error:

chown: data/db: No such file or directory

I've tried all solutions I can find online and I see that the directory exists, but I am not sure what's going on. When I run mongod this is what I get:

Solomons-MacBook-Pro:expense-tracker Solomon$ mongod {"t":{"$date":"2021-11-07T19:02:47.741-08:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}} {"t":{"$date":"2021-11-07T19:02:47.747-08: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":"2021-11-07T19:02:47.748-08:00"},"s":"W", "c":"ASIO",
"id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"} {"t":{"$date":"2021-11-07T19:02:47.748-08:00"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."} {"t":{"$date":"2021-11-07T19:02:47.754-08:00"},"s":"W", "c":"ASIO",
"id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"} {"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"REPL",
"id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}} {"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"REPL",
"id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}} {"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":3449,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"Solomons-MacBook-Pro.local"}} {"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.3","gitVersion":"657fea5a61a74d7a79df7aff8e4bcf0bc742b748","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}} {"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"21.1.0"}}} {"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}} {"t":{"$date":"2021-11-07T19:02:47.758-08: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":"2021-11-07T19:02:47.758-08:00"},"s":"F", "c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":960}} {"t":{"$date":"2021-11-07T19:02:47.758-08:00"},"s":"F", "c":"-",
"id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

Upvotes: 3

Views: 2932

Answers (3)

heilala
heilala

Reputation: 854

On your Mac, if you used Homebrew to install MongoDB, the data directory is created on installation. However, it is not data/db. Instead, on Intel Mac it is /usr/local/var/mongodb and on M1 Mac it is /opt/homebrew/var/mongodb.

To correctly install MongoDB using Homebrew (of course, check what's the latest version):

 brew tap mongodb/brew
 brew install [email protected]

First, check that your MongoDB is running ok by listing the running services using brew:

brew services list

You should see something like:

Name              Status  User File
MongoDB-community started root

If not, try to stop, start or restart the service:

 brew services stop mongodb/brew/mongodb-community
 brew services start mongodb/brew/mongodb-community
 brew services restart mongodb/brew/mongodb-community

For further information about the possible problems, check the log file:

 tail $(brew --prefix)/var/log/mongodb/mongo.log

More details in the official documentation.

Upvotes: 2

Anirudh RK
Anirudh RK

Reputation: 41

I encountered this issue today. Try the following commands in order :

sudo mkdir -p /System/Volumes/Data/data/db --> This will create a new folder, as with the new Catalina OS, the root directory changed.

After this command, you will need to get write permissions. sudo chown -R id -un /System/Volumes/Data/data/db

In order to finally open a mongo db connection, enter the following command: sudo mongod --dbpath /System/Volumes/Data/data/db


For reference, use the following link: https://superuser.com/questions/1458974/macos-switched-root-mongodb-data-folder-to-system-ownership-and-it-cannot-be-cha

Upvotes: 2

After Catalina the root folder is no longer writable. So I created a folder on Desktop called MongoDB, and inside here the tmp & data/db.

And now I run it like this:

mongod --unixSocketPrefix ~/Desktop/MongoDB/tmp --dbpath ~/Desktop/MongoDB/data/db

Upvotes: 0

Related Questions