I recently bought a new iMac and moved all of my files over using Time Machine. The migration went really well overall and within a few hours I had my development machine up and running. After starting an application I’m building I quickly realized that I couldn’t get MongoDB to start. Running the following command resulted in an error about the data/db directory being read-only:
I tried every chmod and chown command known to man and woman kind, tried manually changing security in Finder, compared security to my other iMac (they were the same), and tried a bunch of other things as well. But, try as I might I still saw the read-only folder error when trying to start the server….very frustrating. I found a lot of posts with the same issue but they all solved it by changing security on the folder. That wasn’t the problem on my machine.
This article explains how to quickly set up MongoDB on macOS Catalina. Install homebrew The Missing Package Manager for macOS! Install MongoDB community version. While writing this article the. I searched google to disable the default php of mac, before I install Homebrew. But could not find a good post. Can you please guide me with some resources on how to disable the default PHP. I am sorry for asking all these basic questions. I am windows user my whole life. Just switched to Mac before 1 month.
After doing more research I found out that Catalina added a new volume to the hard drive and creates a special folder where the MongoDB files need to go. The new folder is:
The MongoDB files can then go at:
I ran the following commands to install the latest version of MongoDB using Homebrew (see https://github.com/mongodb/homebrew-brew for more details):
I then went into the MongoDB config file at /usr/local/etc/mongod.conf. Note that it’s possible yours may be located in a different location based on how you installed MongoDB. I changed the dbPath value to the following and copied my existing DB files into the folder:
Finally, I made sure my account had the proper access to the folder by running chown (something I had tried many times earlier but on a folder outside of /System/Volumes/Data):
After that I was able to start MongoDB and everything was back to normal. Hopefully this saves someone a few hours – I wasted way too much time on the issue. 🙂
Question or issue on macOS:
Install Mongodb On Mac Catalina Os
I updated to MacOS 10.15 (Catalina) today. When I run mongod in the terminal it cannot find the /data/db directory:
I tried to install MongoDB with brew:
Any help?
How to solve this problem?
Solution no. 1:
This is the main error:
exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
Catalina has a surprise change: it won’t allow changes to the root directory (this was discussed in a forum thread as well):
Unfortunately, this is not spelled out explicitly in Apple’s Catalina release notes, other than a brief mention in Catalina features:
macOS Catalina runs in a dedicated, read-only system volume
Since the directory /data/db
is coded as MongoDB default, a workaround is to specify a different dbpath
that is not located on the root directory. For example:
This will place MongoDB’s data in your home directory. Just make sure that the path ~/data/db
actually exists.
Alternative method
An alternative method is to follow the instructions at Install MongoDB Community Edition on macOS by leveraging brew
:
This will create some additional files by default:
- the configuration file (/usr/local/etc/mongod.conf)
- the log directory path (/usr/local/var/log/mongodb)
- the data directory path (/usr/local/var/mongodb)
To run mongod
you can either:
Run the command manually from the command line (this can be aliased for convenience):
Run MongoDB as a service using
brew services
. Note that this will run MongoDB as a standalone node (not a replica set), so features that depends on the oplog e.g. changestreams will not work unless you modify themongod
configuration file:
Solution no. 2:
After installing Catalina, you might have a folder on your Desktop called Relocated Items
. You can find the data/db
folder inside the Security
folder.
All I had to do was move the Security/data/db
, specifically data/db
and place it inside my home folder.
You can do this with the Finder app or with the terminal by running the following command:
After that run:mongod --dbpath ~/data/db
It’s up to you to create the alias
Solution no. 3:
Kevinadi already did justice to the question, however this is how I went about solving the problem:
After installing mongodb-community
sudo mkdir -p /System/Volumes/Data/data/db
(Create the data/db folder)sudo chown -R
id -un/System/Volumes/Data/data/db
(Give permissions)mongod --dbpath=/System/Volumes/Data/data/db
(Change dbpath of mongodb)mongod
(Runs well)
I found this article on installing mongodb very useful
Solution no. 4:
found a trick…
delete the ~/data/db entire folder from the directory
then recreate a new one but DO NOT USE mkdir -p /data/db
instead, just use your trackpad to do it
use system way to create folder
this worked for me
Solution no. 5:
Install Mongodb On Mac Catalina Free
Here’s what worked for me:
Install Mongodb On Mac Catalina Island
- Create a folder somewhere e.g. Development/mongodb/data/db
- Open mongod.conf file and update storage.dbPath value to the the newly created folder path
Solution no. 6:
this script can be helpful https://gist.github.com/sturmenta/cf19baa91b1d79d8ae2b305fb7e1f799
🤙🏻🤙🏻🤙🏻
Solution no. 7:
Mac version Catalina made the root folder is no longer writable.
Brew has an updated version of mongodb to use a new path (which it creates itself), /usr/local/var/mongodb
and following these instructions will fix the issue:
brew install [email protected]
where the first VERSION with the fix is 4.2
Solution no. 8:
Your docker image will be able to find your directories regardless of where they are if you use relative directory references ~/Desktop will map your Mac Desktop directory into your image as /Desktop.
Solution no. 9:
Go to ~/Users/Shared
folder.
here, you will find a folder titled ‘Relocated items’ inside that you will be able to find a ‘data’ folder.This ‘data folder contains your mongodb database in`/data/db’.
Now, copy this ‘data’ folder and paste it in your Users/<name-of-your-user-account-with-the-home-icon'>
.
Install Mongodb On Mac Catalina Download
And now open zsh terminal and run mongod --dbpath ~/data/db
and now open a new shell in a separate tab and type mongo
to open the mongo shell and you will be good to go.
Install Mongodb On Mac Catalina
Remember to use mongod --dbpath ~/data/db
each time while running mongod or make an alias.