How to Install and Set Up MongoDB on Windows or Mac

MongoDB is one of the world’s most popular NoSQL database systems, widely used for web applications, mobile apps, APIs, and cloud-based services. Unlike traditional relational databases that store data in tables, MongoDB stores information in flexible, JSON-like documents, making it an excellent choice for applications with dynamic or evolving data structures.

Whether you’re learning database development, building a full-stack application, or setting up a local development environment, installing MongoDB on your computer is a straightforward process. MongoDB provides official installers for both Windows and macOS, allowing you to quickly configure a local database server and start working with your projects.

Update Windows Drivers

In this guide, you’ll learn how to install, configure, and verify MongoDB on both Windows and Mac, along with solutions to common installation problems.

What Is MongoDB?

PC running slow or unstable? Do you want to update drivers?

MongoDB is a document-oriented NoSQL database that stores data as BSON (Binary JSON) documents.

Some key features include:

  • Flexible schema design.
  • High performance.
  • Horizontal scalability.
  • Built-in replication.
  • Powerful indexing.
  • Aggregation framework.
  • Cross-platform support.

MongoDB is commonly used with JavaScript, Node.js, Python, Java, PHP, and many other programming languages.

System Requirements

Before installing MongoDB, ensure your computer meets these basic requirements:

  • Windows 10, Windows 11, or a supported version of macOS.
  • At least 4 GB of RAM (8 GB or more recommended).
  • Around 2 GB of free storage for installation and databases.
  • Administrator privileges.
  • A stable internet connection to download the installer.

Method 1: Install MongoDB on Windows

Step 1: Download MongoDB Community Edition

Visit the official MongoDB website and download the latest MongoDB Community Server installer for Windows.

Choose the MSI installer that matches your system architecture.

Step 2: Run the Installer

Repair PC

Locate the downloaded installer and double-click it.

When the setup wizard opens:

  1. Click Next.
  2. Accept the license agreement.
  3. Click Next.

Step 3: Choose the Installation Type

PC running slow or unstable? Do you want to update drivers?

You’ll typically see two options:

  • Complete
  • Custom

Select Complete unless you need a custom installation path.

Step 4: Install MongoDB as a Service

During installation, you’ll have the option to install MongoDB as a Windows service.

Leave this option enabled if you want MongoDB to start automatically whenever Windows boots.

Click Next.

Step 5: Install MongoDB Compass (Optional)

Some installers also offer MongoDB Compass, the graphical interface for managing databases.

PC running slow or unstable? Do you want to update drivers?

You can install it during setup or download it separately later.

Click Install.

Wait for the installation to complete.

Step 6: Finish Installation

Click Finish once setup completes.

MongoDB is now installed.

Method 2: Verify the Installation on Windows

Open Command Prompt.

Run:

mongod --version

You should see the installed MongoDB version.

To verify the shell (if included with your installation):

mongosh

If the MongoDB shell opens successfully, the installation is working correctly.

Method 3: Start MongoDB on Windows

If MongoDB is installed as a service:

Open Services.

Locate:

MongoDB

Verify that its status is Running.

If it isn’t:

  1. Right-click the service.
  2. Select Start.

Alternatively, you can start it from an elevated Command Prompt:

net start MongoDB

Method 4: Install MongoDB on macOS

Many macOS users install MongoDB using Homebrew.

Step 1: Update Homebrew

Open Terminal.

Run:

brew update

Step 2: Install MongoDB

Add the MongoDB tap if required by the current installation instructions, then install the Community Edition using Homebrew.

Step 3: Start MongoDB

Launch the MongoDB service using Homebrew:

brew services start mongodb-community

Step 4: Verify Installation

Check the installed version:

mongod --version

Open the MongoDB shell:

mongosh

If the shell opens successfully, MongoDB is ready to use.

Method 5: Create Your First Database

Open the MongoDB shell:

mongosh

Create or switch to a database:

use mydatabase

Insert your first document:

db.users.insertOne({
name: "John",
age: 30
})

View the stored data:

db.users.find()

MongoDB automatically creates the database when the first document is inserted.

Method 6: Connect Using MongoDB Compass

MongoDB Compass provides a graphical interface for working with databases.

Open MongoDB Compass.

Enter the default connection string:

mongodb://localhost:27017

Click Connect.

You’ll see your databases, collections, and documents in an easy-to-use interface.

Method 7: Configure MongoDB to Start Automatically

Windows

If MongoDB was installed as a Windows service, it can be configured to start automatically.

  1. Open Services.
  2. Locate MongoDB.
  3. Open Properties.
  4. Set Startup type to Automatic.
  5. Click Apply.

macOS

If installed through Homebrew:

brew services start mongodb-community

The service starts automatically when you log in.

Method 8: Check Whether MongoDB Is Running

Windows

Open Command Prompt:

sc query MongoDB

macOS

Run:

brew services list

The output shows whether the MongoDB service is currently running.

Method 9: Stop MongoDB

Windows

Open Command Prompt as Administrator:

net stop MongoDB

macOS

Run:

brew services stop mongodb-community

This safely stops the database service.

Method 10: Update MongoDB

Keeping MongoDB updated provides new features, performance improvements, and security fixes.

Windows

Download the latest installer from the official MongoDB website and run the upgrade installer.

macOS

If installed through Homebrew:

brew update
brew upgrade mongodb-community

Restart the MongoDB service after updating.

Common Installation Problems and Solutions

“mongod” Is Not Recognized

The MongoDB bin directory may not be included in your system’s PATH environment variable. Add the installation’s bin folder to the PATH or use the full executable path.

MongoDB Service Won’t Start

Check whether another application is using the configured port (default 27017) and verify that the MongoDB data directory exists and has the correct permissions.

Can’t Connect to MongoDB

Ensure the MongoDB service is running and that you’re connecting to the correct host and port, typically localhost:27017.

Permission Errors on macOS

Grant the necessary permissions to Terminal if prompted and ensure Homebrew completed the installation successfully.

Tips for Using MongoDB

To get the best experience:

  • Keep MongoDB updated.
  • Use MongoDB Compass for visual database management.
  • Back up important databases regularly.
  • Secure production databases with authentication.
  • Avoid running production workloads with the default configuration.
  • Monitor disk space, especially for large collections.

These practices improve reliability and help protect your data.

Conclusion

MongoDB is a powerful and flexible NoSQL database that’s easy to install on both Windows and macOS. Whether you use the Windows installer or Homebrew on a Mac, the setup process is straightforward and only takes a few minutes. Once installed, you can start the MongoDB service, connect with mongosh or MongoDB Compass, create databases, and begin building applications that use document-based data storage.

For long-term success, keep MongoDB updated, back up your data regularly, and follow recommended security practices—especially if you move beyond local development to production environments.

Frequently Asked Questions

1. Is MongoDB free to use?

Yes. MongoDB Community Edition is free to download and use for development, learning, and many production scenarios.

2. Do I need MongoDB Compass?

No. MongoDB Compass is optional, but it provides a user-friendly graphical interface for managing databases and is helpful for beginners.

3. What is the default MongoDB port?

MongoDB listens on port 27017 by default.

4. Can I install MongoDB without Homebrew on macOS?

Yes. MongoDB also provides official installation packages and archives for macOS, although Homebrew is a popular and convenient installation method for many users.

PC running slow or unstable? Do you want to update drivers?

GeeksDigit.Com
Logo