How to install MongoDB for Mac in BigSur / Cómo instalar MongoDB en Mac con BigSur

Vaniusha Ramírez
3 min readDec 18, 2020

Mis estimados…

Amamos las actualizaciones de Apple… creo. Actualicé a BigSur y cuando quise ejcutar como siempre mi Mongo Shell, omg! ya no encuentra el folder /data/db en la raíz. A chis. Si yo lo había dejado ahí… y sí, efectivamente, el folder existía y tenía mis datos de las bases de datos anteriores. OMG! ‘qué vamas a hacer!!!!!’ Que no cunda el pánico, les cuento lo que hice. El error dijo, dentro de todo así:

{“t”:{“$date”:”2020–12–17T17:25:23.425–06:00"},”s”:”E”, “c”:”STORAGE”, “id”:20557, “ctx”:”initandlisten”,”msg”:”DBException in initAndListen, terminating”,”attr”:{“error”:”NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the — dbpath command line option, or (2) by adding the ‘storage.dbPath’ option in the configuration file.”}}

Aunque en el directorio sí está, al parecer ahora tenemos que darle permisos adicionales a uno mismo para acceder. Entonces empecemos por el principio

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. :)

--

--