MonogDB is a database that stores information as easy to read "documents". We'll use it to store data in our Node.js and Express stack.
The installation instructions can be found here for all operating systems. However, we'll go through the steps for Mac users together.
- First check if Mongo DB is already installed on your machine by running this command.
which mongoIf you get an output that shows a file path like this
/usr/local/bin/mongoyou already have MongoDB and do not need to continue with the instructions below.
If you get an output that says mongo not found, that means you should install Mongo DB and follow the instructions below.
Mac M1 Chip users follow these steps before continuing past this point.
- Check where Homebrew installs packages.
brew --prefixYou may see /usr/local. We'll update this so that homebrew installs packages in the proper location (/opt/homebrew).
- The following steps will create the proper directory, set up the permissions, and download Homebrew.
sudo mkdir -p /opt/homebrew
sudo chown -R $(whoami):staff /opt/homebrew
cd /opt
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew- Add the Homebrew bin to your PATH variable.
echo export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" >> ~/.zprofile
echo export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" >> ~/.zshrc
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"- Quit out of your terminal completely with
cmd + qand then open it up again.
- Check if the Homebrew install location has been updated.
brew --prefixYou should now see /opt/homebrew and are good to continue.
- Run this command to get the updated brew tap for mongo.
brew tap mongodb/brew- Install Mongo DB Community
brew install mongodb-community@5.0- Start the Mongo service running in the background
brew services start mongodb-community@5.0- After the installation, run the
whichcommand to verify the install was successful.
which mongoIf this has worked correctly, you should see a file path as output.
You are all set and ready to Mongo!