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. Question or issue on macOS: I’m relatively new to MongoDB and am trying to install MongoDB on my Mac with Homebrew, but I’m getting the following error: Error: No available formula with the name 'mongodb' Searching for a previously deleted formula (in the last month). Warning: homebrew/core is shallow clone. To get complete history.
- Today, you'll learn to install the MongoDB community edition on macOS Catalina and higher. Creating Data Folder. Before you install and use MongoDB, you need to create a data/db folder on your computer for storing MongoDB data. Before macOS Catalina, you can create this folder in the user's root directory with the following command.
- If you have already done this for a previous installation of MongoDB, you can skip this step. To install MongoDB, run the following command in your macOS Terminal application: brew install mongodb-community@4.4. Created with Sketch. Alternatively, you can specify a previous version of MongoDB if desired.
Question or issue on macOS:
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:
Here’s what worked for me:
- 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'>
.
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.
Remember to use mongod --dbpath ~/data/db
each time while running mongod or make an alias.
Install Mongodb Macos Catalina Update
Hope this helps!
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:
Install Mongodb Macos Catalina
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. 🙂