Nearby lessons

2 of 22

πŸ’» Installing MongoDB

MongoDB can be installed on different operating systems including Windows, macOS, and Linux. Below are the steps to install MongoDB and MongoDB Compass (GUI) on these platforms.

πŸͺŸ Windows Installation

  1. Go to the MongoDB Community Server download page.
  2. Download the MSI installer for Windows.
  3. Run the installer and follow the setup wizard.
  4. Select β€œComplete” setup type.
  5. Choose to install MongoDB as a Service (recommended).
  6. Install MongoDB Compass (GUI) when prompted or download it separately from MongoDB Compass.
  7. Verify installation: Open Command Prompt and run mongo --version.

🍏 macOS Installation

  1. Install Homebrew if not already installed: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Update Homebrew: brew update
  3. Install MongoDB Community Edition: brew tap mongodb/brew then brew install mongodb-community@6.0
  4. Start MongoDB service: brew services start mongodb-community@6.0
  5. Install MongoDB Compass (GUI) from MongoDB Compass.
  6. Verify installation: mongo --version

🐧 Linux Installation (Ubuntu/Debian)

  1. Import the public key: wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
  2. Create the list file for MongoDB: echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
  3. Update packages: sudo apt-get update
  4. Install MongoDB: sudo apt-get install -y mongodb-org
  5. Start MongoDB: sudo systemctl start mongod
  6. Enable MongoDB to start on boot: sudo systemctl enable mongod
  7. Install MongoDB Compass (GUI) from MongoDB Compass (Debian/Ubuntu package).
  8. Verify installation: mongo --version

⚑ Starting MongoDB Shell and Compass

After installing MongoDB, you can start the MongoDB shell and MongoDB Compass to interact with your databases:

  • Open Command Prompt / Terminal.
  • Type mongosh to open the MongoDB shell.
  • Open MongoDB Compass to connect to your local MongoDB instance using mongodb://localhost:27017.
  • Start creating databases, collections, and documents either via the shell or Compass GUI.

πŸ’‘ Notes

  • MongoDB Community Edition is free and open-source.
  • MongoDB Compass provides a GUI interface for easier database management.
  • Always verify your MongoDB installation using mongo --version or mongosh --version.
  • MongoDB Compass allows visual CRUD operations and data exploration without using the shell.
Keep Going!MongoDB - Create & Drop Database / Collections