Jack Downson

Jack Downson


How to Installing MongoDB on macOS Catalina

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!

The Problem

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 data/db to /System/Volumes/Data/data/db .

You could, in theory, place data/db wherever you like. But /System/Volumes/Data/ seems like a more secure option than somewhere like Documents.

1. Disable SIP

To access /System/, however, requires disabling macOS’s SIP (System Integrity Protection), which prevents modification to that directory. To disable SIP, you need to:

  • Boot into recovery mode by restarting and holding CMD + R during the boot-up.
  • Open up the terminal (which can be found under ‘Utilities’ in the top menu).
  • Inside the terminal, run csrutil disable. You can now reboot in normal mode.

2. Move Your /data/db Folder out of the Root

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.

3. (Re)Install MongoDB

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 homebrew-core.

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 

4. Run MongoDB From the Terminal

If everything’s worked correctly, you should now be able to run mongod and 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

5. Create a Terminal Alias

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 ~/.zshrc:

alias mongod="sudo mongod --dbpath /System/Volumes/Data/data/db"

This means 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 #programming

What is GEEK

Buddha Community

How to Installing MongoDB on macOS Catalina

Install MongoDB Database | MongoDB | Asp.Net Core Mvc



#mongodb #mongodb database #mongodb with c# #mongodb with asp.net core #mongodb tutorial for beginners #mongodb tutorial

Query of MongoDB | MongoDB Command | MongoDB | Asp.Net Core Mvc


#mongodb tutorial #mongodb tutorial for beginners #mongodb database #mongodb with c# #mongodb with asp.net core #mongodb

Insert & Save method in MongoDB | Inserting Document | CRUD Operation in MongoDB


#mongodb #mongodb tutorial for beginners #mongodb tutorial #mongodb database #learn mongodb

Execute MongoDB Command | Create, Drop and Select Database | MongoDB | Asp.Net Core Mvc


#mongodb #mongodb with asp.net core #mongodb with c# #mongodb tutorial for beginners #mongodb tutorial #learn mognodb

MongoDB Delete Document | Remove, DeleteOne and DeleteMany Methods | Asp.Net Core


#crud operation #mongodb #mongodb tutorial for beginners #mongodb tutorial #mongodb database #learn mongodb