Skip to content

Installing MongoDB on Windows: A Step-by-Step Guide

Comprehensive Learning Hub: Our platform caters to a wide range of academic disciplines, encompassing computer science and programming, school education, professional development, commerce, software tools, competitive exam preparations, and various other subjects, facilitating learning for...

Installing MongoDB on Windows: A Step-by-Step Guide
Installing MongoDB on Windows: A Step-by-Step Guide

Installing MongoDB on Windows: A Step-by-Step Guide

In this guide, we will walk you through the process of installing and running MongoDB on Windows 11.

Downloading MongoDB

First, download the MongoDB Community Server from the MongoDB Download Center. Choose the Windows x64, Version 7.0.4, and msi package. For those who prefer, a ZIP version of MongoDB can also be downloaded from the official MongoDB website.

Once downloaded, run the msi file and accept the End-User License Agreement. During the installation process, choose the "Complete" option to install all program features.

Extracting and Setting Up MongoDB

After installation, extract the ZIP archive to a location on your computer where you have write permissions. To run MongoDB without installation, navigate to the "bin" folder within the MongoDB directory and execute the command with the path to the directory where you want to store MongoDB data files.

Enabling the MongoDB Service

The MongoDB service on Windows 11 must be enabled by a user account typically named "Network Service" or a dedicated MongoDB service user. This user must be a member of the local "Administrators" group and optionally the "Users" group to have the necessary permissions for running the service. When setting up the service, select "Run service as Network Service" and copy the data directory path.

Running the MongoDB Server

To run the MongoDB server (mongod), open the command prompt and start the MongoDB service. However, an error ("C:/data/db/ not found") may occur, requiring the creation of the "data" and "db" folders in the C drive.

Connecting to the MongoDB Server

To connect the server (mongod) with the mongo shell, open a new command prompt window and type the command. MongoDB should now be running locally on your Windows 11 system without the need for admin rights.

Interacting with MongoDB

Interact with MongoDB using the MongoDB shell by running the command. It's worth noting that the traditional MongoDB shell has been deprecated from MongoDB version 5.0 onward, and the recommended shell for interacting with MongoDB databases is now mongosh.

Creating and Using Databases

To create a new database in the system, use the command . This command creates a new database if it does not exist, or uses the existing database if it does. To insert a document into a collection, use the command .

Setting Environment Variables

After setting up MongoDB, set environment variables by pasting the bin path in the system's environment variable. This will allow you to easily access MongoDB commands from any command prompt window.

User Permissions

The user running MongoDB services must have membership in the Performance Monitor Users and Performance Log Users groups. This is necessary for the proper functioning of the MongoDB service.

System Requirements

MongoDB 4.4 or higher (64-bit only) is required for installation on Windows 11. Supported operating systems include Windows Server 2022, Windows Server 2019, and Windows 11.

That's it! You've successfully installed and set up MongoDB on your Windows 11 system. Happy coding!

Read also:

Latest