How to install MongoDB for Mac in BigSur / Cómo instalar MongoDB en Mac con BigSur
By: Vaniusha Ramírez
Tags: Mongo Shell, Macos Big Sur, Mongod, Mongodb

1.INSTALL MONGO DB WITH HOMEBREW FROM BASH

Bueno, si eres desarrollador y trabajas con macOS, seguro has oído hablar de homebrew, el package manager por excelencia macOS y Linux. Entonces primero asegúrate de tenerlo instalado, continuaré en inglés para facilitar el acceso a todos: First, check if you have Homebrew installed:

$ brew --version

If any version found, then install Homebrew with:

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

Then install Mongo DB, if is not there already:

a) Find the mongoDB tap: $ brew tap mongo/brew

b) Install: $ brew install mongodb-community

(This is for install the free version, if other, install the enterprise version instead)

In MacOs BigSur, Mongo (mongo, mongod, mongodumb, mongoexport, mongofiles, mongoimport, mongoreplay, mongorestore, mongos, mongostat y mongotop) should be installed in usr/local/bin, but the mongo.config file is on usr/local/etc. If you install previously like me, your files have to be there as your first data/db storage location, so you can avoid this step.

2. CONFIGURE THE DATA STORAGE LOCATION FILES

In BigSur, seems to be a data/db folder already for other purposes in /System/Volumes/Data/data/db so probably we can’t locate it there as well, Then instead, we can locate any other place the data/db folders required for setting up MongoDB, if you already have like me, just locate with the path, otherwise, create the folder /data with the other folder /db inside. After this, with the folders existing, the issue in BigSur is that even when we will give permissions like:

sudo chown -R `id -u` /data/db

or:

sudo chmod -R go+w /data/db

Seems like each time while executing mongod command, we have to set it again and told where is this data/db file located, and we will have while executing mongod always the error of not finding, then instead of set the path always, as a quick fix I did is set an alias to execute and to locate which data/db folder we will use:

$ alias mongod --dbpath ~/data/db

After this, each time I’m executing on bash mongod, is running well.

Now, to make your alias permanent we have to write it in our bash profile:

Open the bash profile:

$ nano ~/.bash_profile

Then, in the editor add:

#My permanent alias for mongoDB

alias mongod= "mongod --dbpath ~/data/db"

Finally, close the terminal and while launching bash again will read the profile settings and will work permanently. If you want to edit or remove anytime, open again the nano bash profile. You can execute the command now: $ mongod (to raise the deamon) and without closing this terminal window, open a new one to execute: $ mongo (as usual, it will open the MongDB Shell with the established connection).

Another option maybe is to set the mongo.config file, but while setting I could not find the way to Mongo to take the config settings given always, so, the same problem. Seems to take settings given only while session, but always setting config file not seems like the fastest option.

So, hope this quick fix helps you if troubling like me after updating my MacOS from Catalina to BigSur. :)