But before you proceed to install MongoDB using homebrew, type this in the terminal or it might throw errors during the MongoDB installation. Since data/db cannot be accessed as Catalina has. Apple can’t check app for malicious software. Using an app that can’t be checked for malicious software might harm your Mac or compromise your privacy. If you’re certain that the app you want to use is from a trustworthy source, you can override your Mac security settings to open it. See the Apple Support article Safely open apps on your Mac. To install Catalina on another Mac, first make sure it's powered off, then simply plug in the USB installer you created and turn the Mac on. When you hear the boot tone, hold down the Option.
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.
Install MongoDB on MacOS using Homebrew
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
14th Feb 2020I had to reconfigure my Macbook after sending it for repairs. During the reconfiguration period, I noticed the instructions I linked to in “Setting up a local MongoDB connection” were outdated.
Here’s an updated version on how to install MongoDB on a Mac.
There are a few steps:
First, you install Homebrew. If you’re curious about what Homebrew is, read this article.
Second, find the MongoDB tap.
Third, install MongoDB.
MongoDB is now installed on your computer.
Preparations (Before MacOS Catalina)
Before you can use MongoDB, you need to create a /data/db
folder on your computer to use MongoDB. You can create this folder with the following command:
You also need to give permissions to use it:
Now you can follow the rest of the article to set up your MongoDB connection.
Preparations (MacOS Catalina onwards)
Apple created a new Volume in Catalina for security purposes. If you’re on Catalina, you need to create the /data/db
folder in System/Volumes/Data
.
Use this command:
Then, use this command to give permissions:
Using MongoDB
In the past, I can run the mongod
command to start MongoDB. This no longer works out for the box from MongoDB v4.2.3 onwards.
The best way to start MongoDB now is via brew services
.
Starting MongoDB
Use this command:
MongoDB will start as a background service. Here’s what you’ll see:
You can use start
instead of run
. start
will start MongoDB automatically when you login into your Macbook. I prefer run
since I don’t want MongoDB to be running all the time.
Install Mongodb Catalina Free
Checking if MongoDB is running
Use this command:
Homebrew will list all running services. If MongoDB is running, mongodb-community
will have a status set to started
.
The Mongo Shell
Install Mongodb Catalina Operating System
If MongoDB is running, you should be able to access the Mongo shell with the mongo
command.
Stopping MongoDB
Use this command:
Homebrew will stop MongoDB and let you know.
Install Mongodb Macos Catalina
Aliases to make these easier
It’s a chore typing brew services run mongodb-community
every time I want to start MongoDB.
I created some aliases to make things easier for me. Here are my aliases:
What’s next?
If you haven’t already, you should learn how to set up a local MongoDB connection.
Install Mongodb Catalina Mac
If you enjoyed this article, please tell a friend about it! Share it on Twitter. If you spot a typo, I’d appreciate if you can correct it on GitHub. Thank you!