How to install MongoDB in Windows

Abhigyan Singh 10th Sep 2020

In this tutorial, we will show you the best way to install MongoDB in the windows machine.

Prerequisites

You should be familiar with the Windows command prompt (cmd).

Download MongoDB

you can be downloaded from its official website. You can download the MongoDB from here. Once you navigate to this website, you will find, there are different versions are available of MongoDB for the different operating systems on their official website.

So we have to choose according to our system configuration and download it.
Here you can see tow types of files are available i.e zip and MSI file. You can download the zip file.

Note: MongoDB doesn't require explicit installation like other software or application. Just download the zip file and configure it in any directory.

After downloading, unzip, or extract it to your desired location. Here we kept in E:\mongodb

MongoDB folder structure

There is a 'bin' folder available inside the folder and it contains approx. 13 application file that helps to run.

E:\mongodb\bin

Data Directory of MongoDB

MongoDB requires a data directory to store the data. You can crate this folder manually in any location "C:\data",  will not create it automatically and this will be the path of storage location.

Configuration File

You can create a configuration file inside the folder called “mongo.config”. It is just like a text file. Here you can specify the storage data path location

##store data here 
dbpath=D:\mongodb\data

Run MongoDB server

The server will start by using the below command:

mongod --dbpath="C:\data" --storageEngine=mmapv1

Open a command prompt (cmd) inside the bin folder and type the above command. It will start the server and point your storage path to your given location. It also set the storage engine type.

 

From the above image, you can see that it show 'waiting for connections on port 27017'

Connect to MongoDB

Open another command prompt in the same bin location and type below command:

Command : mongo

It will connect with you.

Now you can see that the mongo server says the connection is accepted.

Now you are ready to write code or queries.

Test MongoDB

You can write the below command to list the default database

Command : show dbs

You can also read: Integrate MongoDB in CodeIgniter for database operation

Authored By Abhigyan Singh

He is a continuous blogger and has blogged on different topic. He loves to surf Internet and always trying to get new Idea about new Technology and Innovations and sharing these great information to all the technology lovers.

ALSO ON DISCUSS DESK