Mongo DB is one of the popular databases in the market right now . Versatile , fast , and easy to work with . If you want to get started with MEAN or MERN stack development , you will need a working mongo DB instance . Although we can use online solutions to learn the basics of mongo , its always convenient and faster to work with a local instance of Database server . So here we are going to install Mongo DB and its tools on Windows 11 .

Note : although this tutorial is made on windows 11 , its fully compatible with earlier versions of windows .

Now , lets get started with mongo DB

Contents

Installing Mongo DB

For installation , we have 2 ways available either we can go with command line package manager option or we can use standalone windows MSI installer .

There is slight difference in both . For complete development setup of mongo DB , we need multiple components like mongo DB server , mongo shell , mongoDB compass ( its GUI tool to manage mongo DB instances , like mysql workbench ) . In case of installer all components are installed directly . In case of winget package manager we need to install it manually .

Command Line Installation

Before installation we need to search for the package . Enter following command to search for mongo related packages .

As you can see , all the search results related to mongo are presented .

For installation , we need to use ID of package with install command , as seen in picture below .

Mongo packages available to install with winget

Here , winget is our windows package manager . If you are on windows 11 , its inbuilt .just open windows terminal / command prompt / PowerShell .

winget install command output

This way you have to install all the required packages from command line .

But if you are not a command line fan or if you prefer a ready to use way , we have installer of Mongo DB for you . Lets see how to install mongo DB with MSI installer .

Mongo DB installation Using Mongo DB MSI installer

As you have already predicted next step , yes we need to download the installer .

So , get it fast from this link.

Its a mongo DB community installer . We have other options to explore also like Mongo DB Atlas , Mongo DB Enterprise . But its for some other day . Besides , community version has all the features that other installation instances have . Just we are missing the official mongo DB support . But no worries I have got you covered . 😉😎

Now I assume , that you have downloaded the installer , lets start the procedure .

Launch the installer by double clicking it . You will see screen like this.

Mongo DB installer Welcome Screen

Just press next and you will be redirected to next screen of setup wizard. Now ,here is license agreement that we have to accept before proceeding . click accept and press next to proceed.

License agreement

Here , we are provided with 2 options , complete installs all the components and custom gives us flexibility to choose components which we require . Lets proceed with complete installation . click complete and next.

Here , we have to choose our mongo DB installation location . I will recommend you to keep it as it is . But , if you are running out of space on your C drive , you can change it to other drive .

Installation location selection

Now , that we have configured our installation location , we can proceed with next step.

Here , we are setting up our mongo DB service . If you have less RAM on your machine ( below 4GB ) i would not recommend you to keep this option checked . But if you have good enough machine for development , you should keep this option on .

This will create a Mongo DB service . Services keep running in background and look for invocation by user or other program , thereby consuming RAM resource of machine .

Note : If you have less ram , you can keep this option off and still be able to use mongoDB . But you have to launch mongod.exe file by yourself , every time you use mongoDB.

MongoDB as a service

Moving towards next step . Now , its an optional step . If you are a big fan of managing databases with command line , mongo shell is already available . But if you want a convenient GUI based management tool , Mongo DB compass is for you . Just check the box at bottom and installer will take care of rest .

Mongo DB compass

Up to this point , we have just configured the installer . But installation will begin now , after clicking Install option and giving permission .

And now our mongo DB is installed on our local machine .

Now , lets get started with basic stuff of mongo like entering mongo shell , playing with some basic commands and making ourself familiar with the mongo environment.

Working with Mongo DB

Entering and exiting mongo shell

To interact with mongo DB server , we are provided with a program called mongo shell . Mongo shell is a command line tool to manipulate the Database , collections and documents .

To enter mongo shell , just open terminal and enter keyword mongo .

You might get following error in case if your path is not set properly .

Mongo not recognized error

To fix this , we need to add mongodb installation folder to path environment variable . Lets add it .

Search for path in windows search . And open ‘Edit the system environment variables’ option .

Now click option Environment variables from right bottom .

Now click on path , as shown in below and click edit .

Now in this window , make sure you have not selected any option already . Because if any option is selected , it will get over written .

Now click on browse option , and locate your mongo installation .

We need the bin folder , as it contains all the binaries of mongo installation. Now click ok on all windows opened.

Now close terminal and open new one and try to enter mongo shell .

entering mongo shell

When you launch mongo shell for first time , you will be welcomed to mongo shell and given some basic guidlines about how to use it .

To exit mongo shell , just type exit and press enter .

exiting mongo shell

Basic operations with mongo shell

These operations will help navigate the DB available . But using mongo DB requires a complete dedicated guide .

Listing Databases

As mongo DB is a non relational database , here we don’t have tables and rows and columns . We have DB > collection > document structure .

To list all DB , we use show dbs ; command .

show db command in action

Selecting a DB

to select existing DB , use keyword is used .

Listing all collections

To list collections in selected DB , we will use keyword show with another keyword collections as follows .

Fetching Documents from collection

To fetch all the documents from a collection , we use find() method .

Syntax is as follows

db.<collection name>.find();

Insert a Document

In mongo DB , a document is a JSON object . Which means key value pairs are stored .

Syntax is as follows .

db.<collection name>.insert({"key":"value","key":"value","key":"value","key":"value"});

So these are some basic operations to get started with a fresh installation of mongo DB .

So we did setup of a fresh instance of mongo DB on windows 11 host and learnt some basic operations to get started with mongo DB .

2 Responses