How to Install MongoDB in macOS

MongoDB Setup

Install Homebrew

  1. Visit: https://brew.sh/
  2. Run this command in terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


Verify brew is installed by typing:

brew


Install MongoDB

  1. Visit: MongoDB Install Guide


Prerequisite

  1. Install Xcode (if not already):
xcode-select --install


Step-by-step Commands:


Tap MongoDB formula:

brew tap mongodb/brew


Update brew:

brew update


Install MongoDB:

brew install mongodb-community@8.0


Start MongoDB service (in a fresh terminal):

brew services start mongodb-community@8.0


Use MongoDB


Start Mongo Shell:

mongosh


Check databases:

show dbs

(Default databases will appear)


MongoDB Compass

  1. Download from: https://www.mongodb.com/products/tools/compass
  2. Move downloaded file to Applications
  3. Open MongoDB Compass
  4. Connect using localhost