How to install and run MongoDB on macOS - Catalina

Tanvi Rastogi
2 min readJun 17, 2021

Are you struggling while doing MongoDB setup on your upgraded version of Mac machine? If yes, then follow these simple steps which will definitely help you and save you time.

Open your terminal, and let’s get started!

INSTALL MongoDB Community Edition

Step 1: Install Homebrew on your local machine, incase if it is already installed, skip this step.

bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

If you want to know more about Homebrew: https://brew.sh/

Step 2: Tap the MongoDB Homebrew Tap which will download the official homebrew formula for MongoDB by running the following command:

brew tap mongodb/brew

To know more about tap follow this link: https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap

Step 3: Install MongoDB

brew install mongodb-community@4.2

You are all set to use MongoDB on your machine now.

RUN MongoDB Community Edition

Step 4: To use the DB, start / run the MongoDB instance

brew services start mongodb-community 
OR
brew services start mongodb-community@4.2

To stop the MongoDB service:

brew services stop mongodb-community
OR
brew services stop mongodb-community@4.2

NOTE: Used community edition 4.2 at my time.

Step 5: Create a directory: As you may be running MongoDB for the first time locally, you need to create a data directory — a directory where your data will be written.

But, you may face a problem while creating a /data/db folder directly.

After Apple’s update in the macOS Catalina version, now you need to create /data/db folder in System/Volumes/Data

Run this command to create a data/db folder locally:

sudo mkdir -p /System/Volumes/Data/data/db

Step 6: Give read/write access permissions to the folder

sudo chown -R `id -un` /System/Volumes/Data/data/db

To verify that MongoDB is running:

brew services list

Connect and Use MongoDB

In case you want to do some DB operations on mongo shell directly, you need to connect one to the running MongoDB instance.

Issue the following command in the terminal and you are good to go.

mongo

You can always visit the MongoDB official website for exploring the queries and commands.

Some of the basic commands that you should be using very often are:

A Few Examples:

I hope you found it helpful. Thanks for reading. :)

--

--