In this tutorial, we will show you the best way to install mongoDB in windows machine.
You should be familiar with the Windows command prompt (cmd).
MongoDB can be downloaded from their official website. You can download mongoDB form here. Once you navigate to this website, you will find, there are different versions are available of mongoDB for different operating system in 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 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 ‘bin’ folder available inside the mongoDB folder and it contain approx. 13 application file that helps mongoDB to run.
Data Directory of mongoDB
MongoDb require a data directory to store the data.You can crate this folder manually in any location “C:\data”, mongoDB will not create it automatically and this will be path of mongoDB storage location.
You can create a configuration file inside the mongoDB folder called “mongo.config”. It is just like a text file. Here you can specify the storage data path location
##store data here
Run mongoDB server
mongoDB server will start by using below command:
mongod --dbpath="C:\data" --storageEngine=mmapv1
Open a command prompt (cmd) inside bin folder and type the above command. It will start the mongoDB server and point your storage path to you 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 same bin location and type below command:
Command : mongo
It will connect with the mongoDB.
Now you can see that mongo server says connection is accepted.
Now you are ready to write mongoDB code or queries.
You can write below command to list the default database
Command : show dbs
You can also read : Integrate MongoDB in CodeIgniter for database operation