How to Install MongoDB 8 and MongoDB Shell on Windows 11

This guide will show you step-by-step instructions on installing MongoDB 8 and MongoDB Shell (mongosh) on the Windows 11 operating system.

YouTube Video

Step 1: Download MongoDB 8 Installer

  1. Visit the MongoDB Website:
    Go to the official MongoDB Community Edition download page:
    https://www.mongodb.com/try/download/community.

  2. Select the Correct Version:

    • Version: Choose MongoDB 8.
    • Platform: Select Windows.
    • Package: Choose the MSI installer for an easy setup.
  3. Download the Installer:
    Click the Download button to start downloading the installer.

Step 2: Install MongoDB 8

  1. Run the Installer:
    Locate the downloaded .msi file (e.g., mongodb-windows-x86_64-8.x.msi) in your Downloads folder and double-click it.

  2. Follow the Installation Steps:

    • License Agreement: Accept the terms and click Next.
    • Setup Type: Choose Complete for the default installation, which includes MongoDB Server and tools.
    • Service Configuration:
      • Keep the default settings to run MongoDB as a Windows service.
      • This allows MongoDB to start automatically on system boot.
    • Data Directory: By default, MongoDB stores data in:
      C:\Program Files\MongoDB\Server\8.0\data
      
  3. Start Installation:
    Click Install and wait for the installation to complete.

  4. Finish Setup:
    Once the installation is complete, click Finish.

Step 3: Verify Automatic PATH Configuration

The MongoDB installer automatically adds the bin directory to the system PATH. This allows you to run MongoDB commands from the terminal without additional configuration.

  1. Open Command Prompt:

    • Press Win + R, type cmd, and press Enter.
  2. Check MongoDB Server Version:

    • Run the following command:
      mongod --version
      
    • You should see the version details of MongoDB Server.
  3. Check MongoDB Shell (mongosh):

    • Run:
      mongosh --version
      
    • This verifies that the MongoDB Shell is installed and accessible globally.

If PATH Is Not Configured Automatically

In rare cases where the PATH is not configured, follow these steps:

  1. Locate the MongoDB installation directory. The default path is:

    C:\Program Files\MongoDB\Server\8.0\bin
    
  2. Add MongoDB to the PATH:

    • Open the Start Menu and search for Environment Variables.
    • Click Edit the system environment variables.
    • In the System Properties window, click Environment Variables.
    • Under System variables, find Path and click Edit.
    • Click New and paste the path to MongoDB’s bin directory (e.g., C:\Program Files\MongoDB\Server\8.0\bin).
    • Click OK to save changes.
  3. Verify Again:

    • Open a new Command Prompt and repeat the verification steps above.

Step 4: Install MongoDB Shell (mongosh)

  1. Visit the MongoDB Shell Download Page:
    Go to https://www.mongodb.com/try/download/shell.

  2. Select Platform:

    • Choose Windows and download the .msi installer.
  3. Install mongosh:

    • Run the downloaded installer and follow the setup wizard.
    • By default, mongosh will be installed in:
      C:\Program Files\MongoDB\mongosh
      
  4. Verify Installation:

    • Open a new Command Prompt and type:
      mongosh --version
      
    • You should see the version of the MongoDB Shell.

Step 5: Start MongoDB Server

  1. Start MongoDB as a Service:

    • MongoDB is installed as a Windows service. To start it, open Command Prompt and run:
      net start MongoDB
      
    • If the service is already running, you’ll see a message indicating so.
  2. Verify Connection:

    • Open mongosh by typing:
      mongosh
      
    • This connects to the MongoDB server. If successful, you’ll see the MongoDB Shell prompt:
      test>

Step 6: Basic Commands to Get Started with MongoDB Shell

Once you’re in the MongoDB shell (mongosh), try these basic commands:

  1. Show Databases:

    show dbs
    
  2. Create or Switch to a Database:

    use mydatabase
    
  3. Insert a Document:

    db.mycollection.insertOne({ name: "John", age: 30 })
    
  4. Find Documents:

    db.mycollection.find()
    
  5. Exit the Shell:

    exit

Conclusion

You’ve successfully installed MongoDB 8 and MongoDB Shell (mongosh) on Windows 11. With MongoDB up and running, you’re ready to start building scalable and flexible applications. Whether you’re storing data, running queries, or managing collections, MongoDB provides powerful tools for modern development. Happy coding!

Comments