1. Installation on Different Operating Systems

Windows

  1. Download MongoDB:

  2. Install MongoDB:

    • Run the downloaded MSI file.
    • Follow the setup wizard to install MongoDB.
    • Select “Complete” setup type.
    • Choose to install MongoDB as a service (recommended).
  3. Add MongoDB to the PATH:

    • Add the MongoDB bin directory (e.g., C:\Program Files\MongoDB\Server\X.Y\bin) to your system’s PATH environment variable.

macOS

  1. Install Homebrew:

  2. Install MongoDB:

    • Open Terminal and run:
        brew tap mongodb/brew
      brew install mongodb-community
        
  3. Start MongoDB:

    • Run:
        brew services start mongodb-community
        

Linux

  1. Import MongoDB public GPG Key:

    • Run:
        wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
        
  2. Create a List File:

    • Run:
        echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs) mongodb-org 6.0" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
        
  3. Install MongoDB:

    • Update package list:
        sudo apt-get update
        
    • Install MongoDB:
        sudo apt-get install -y mongodb-org
        
  4. Start MongoDB:

    • Run:
        sudo systemctl start mongod
        
  5. Enable MongoDB to start on boot:

    • Run:
        sudo systemctl enable mongod
        

2. Configuration and Basic Setup

  • Configuration File:

    • The default configuration file is usually located at /etc/mongod.conf on Linux, or C:\Program Files\MongoDB\Server\X.Y\bin\mongod.cfg on Windows.
    • Modify this file to set options like bindIp, port, and dbPath.
  • Basic Setup:

    • You can configure settings like security, storage engines, and replication in the configuration file.
    • For example, to bind MongoDB to localhost, set bindIp: 127.0.0.1 in mongod.conf.

3. Starting and Stopping MongoDB Service

  • Windows:

    • Start MongoDB:
      • Use the Services application (search “Services” in Start Menu) to start the MongoDB service.
    • Stop MongoDB:
      • Similarly, stop the MongoDB service using the Services application.
  • macOS/Linux:

    • Start MongoDB:
      • Run:
          sudo systemctl start mongod   # Linux
        brew services start mongodb-community   # macOS
          
    • Stop MongoDB:
      • Run:
          sudo systemctl stop mongod   # Linux
        brew services stop mongodb-community   # macOS
          

4. MongoDB Compass Overview (GUI Tool)

  • Download and Install:

  • Features:

    • Data Visualization: View and interact with your data through a graphical interface.
    • Query Builder: Build and execute queries using an intuitive GUI.
    • Schema Exploration: Analyze and visualize your data schema.
    • Performance Monitoring: Monitor database performance metrics.
  • Basic Usage:

    • Open MongoDB Compass and connect to your MongoDB server using the connection URI (e.g., mongodb://localhost:27017).
    • Explore databases, collections, and documents.
    • Use the built-in tools to run queries, view performance statistics, and manage indexes.