Recently, I started a new developer job and switched from a Windows to a Mac. The switch was mostly very smooth, with one main problem: setting up MongoDB. The problem is related to the latest major macOS release, Catalina, and in this article, I’ll share my solution.
Setting up MongoDB to run on Catalina is more time-consuming than it should be, but hopefully, this article will save you from some of the headaches I went through!
By default, MongoDB stores database information in the root folder, in
data/db. But the Catalina update provides read-only access to the root. Based on this suggestion from Dom Berk, my solution was to move
You could, in theory, place
data/db wherever you like. But
/System/Volumes/Data/ seems like a more secure option than somewhere like
/System/, however, requires disabling macOS’s SIP (System Integrity Protection), which prevents modification to that directory. To disable SIP, you need to:
CMD + Rduring the boot-up.
csrutil disable. You can now reboot in normal mode.
If you have data inside
/data/db in the root, you can move it by providing temporary write-access to the root.
Once SIP is disabled, open the terminal and type
sudo mount -uw /.
You can now move your folder out of the root and into
/System/Volumes/Data/. This read-write ability will only last for the current session.
Next, I wanted to do a clean install of MongoDB. I tried a handful of different options, but Brew was the most convenient. For those who have tried to follow older tutorials,
mongodb has been removed from
Now, you’ll need to use
mongo-community, which can be accessed as follows:
brew tap mongodb/brew brew install mongodb-community brew services start mongodb-community
If everything’s worked correctly, you should now be able to run
mongo — and see something other than a
command not found error!
If we just run
mongod, we’ll get errors that tell us the database directory is read-only. That’s because, by default, the command assumes that our database folder is in the root.
So, when running
mongod, we need to specific
--dbpath /System/Volumes/Data/data/db . Because we’re using
/System/, we also need to use
sudo. The full command is:
sudo mongod --dbpath /System/Volumes/Data/data/db
That’s a bit tiresome to type every time. So, if you’re mostly using the same database path, I’d recommend setting up an alias.
If you use Zsh, you can add the following to
alias mongod="sudo mongod --dbpath /System/Volumes/Data/data/db"
mongod will work pretty much as you’d expect. Just be aware that, if you ever need to change the
--dbpath , you’ll need to disable this alias.
I hope that’s saved you some time and some frustration! Credit is due to Dom Berk, whose solution I’m building on in this article.
#mongodb #mongodb database #mongodb with c# #mongodb with asp.net core #mongodb tutorial for beginners #mongodb tutorial
#mongodb tutorial #mongodb tutorial for beginners #mongodb database #mongodb with c# #mongodb with asp.net core #mongodb
#mongodb #mongodb tutorial for beginners #mongodb tutorial #mongodb database #learn mongodb
#mongodb #mongodb with asp.net core #mongodb with c# #mongodb tutorial for beginners #mongodb tutorial #learn mognodb
#crud operation #mongodb #mongodb tutorial for beginners #mongodb tutorial #mongodb database #learn mongodb