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.
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:
However, if you are using latest Mac version Catalina then 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: Follow the link to install and update mongodb-community-edition. /data/db not found/data/db not found MAC OS Catalina/data/db not found mongodb.
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. 🙂
In this tutorial I am going to talk about how you can install MongoDB on MacOS in an easy way. I have gone through many tutorials online, but I have been really upset with those tutorials. Most of the tutorials are outdated and old. So I decided to create this tutorial in which i can show you a better and easy way to setup MongoDB on MacOS.
In order to install MongoDB on MacOs, I would suggest using Homebrew.
Please open up the MacOs command line tool and paste the following command to setup MongoDB on MacOS.
Once you entered the given above command, your MacOS terminal will start some process. Those processes are nothing but related to creating some folder in your local machine where all the Homebrew related settings are kept.
After finishing the installation process, check your Homebrew dependencies.
Hit the below commands to install MongoDB
After MongoDB successfully installed in your machine, then create a folder to store MongoDB data using given below command
Use the given below command to assign the proper permission to MongoDB data folder.
We’ve successfully installed the MongoDB on MacOS also assigned the proper permission. Now it’s time to run mongo daemon service. This service makes the connection and performs the task in the background. Hit the following command to run MongoDB.
Now your apps are all set to communicate with MongoDB. Mongo is correctly working in the background with the help of mongo daemon. You might also check which MongoDB version you are working on, just hit the below command in the terminal.
mongo --version output
Above command will tell you which MongoDB version is running in your local machine. Using the latest version has always been a good practice. It protects you from compatibility chaos with client-side app.
However, if you are using latest Mac version Catalina then 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:
Follow the link to install and update mongodb-community-edition