Wednesday, 7 October 2015

Installing MongoDB in windows

 

 

STEP 1: Download MongoDB from official website

- Choose platform as windows which is selected by default.
- Select Version - Windows 64-bit legacy or Windows 32- bit if your operating system is 32-bit.
- Click on Download(zip) 

 

 

STEP 2: Extract the mongodb zip file in your windows directory

- Extract the downloaded mongodb-zip in your Windows directory using any zip decompresser.



STEP 3: Creating required folders and files

- After extracting the mongodb-zip to your Windows directory, you need to create a few folders and a files IN IT.
- Create a folder named data
- Create a folder named log
- Using text editor like notepad, create a file named mongo and save it with extension .config



- In the created log folder, you need to create a file named mongodb  and save it with extension .log



 

STEP 4: Making entries in mongo.config file

- Open mongo.config file using a text editor like notepad or wordpad.
- We need to make three entries in this file, which are:
dbpath
logpath
dialog

- dbpath specifies the path of data folder which you have created.
- logpath specifies the path of log folder which you have created.
- dialog specifies the operations on your database.

- Refer the image below and make entries accordingly in mongo.config file

 

STEP 5: Setting path 

  1. From the Desktop, right-click the Computer icon and select Properties. If you don't have a Computer icon on your desktop, click the Start button, right-click the Computer option in the Start menu, and select Properties.
  2. Click the Advanced System Settings link.
  3. In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
  4. In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button.
  5. Add the path of mongodb's bin folder. (Refer Image)
  6. Click on OK. 
  7.  
     

STEP 6: Running mongodb server and client

- Open two command prompt windows.

- In the first command prompt window type mongod --dbpath "C:\mongodb-win32-x86_64-3.0.6\data" and press enter.
-You will see a message  'Waiting for connection'
 (mongod is mongodb's server)
(--dbpath specifies the path of mongodb's data folder which we had created in step 3.)

 - In the second command prompt window type mongo and press enter.
(mongo is mongodb's client)
- You will get connected to the test database of mongodb.

See the image below

NOTE:

* We had created the data folder of mongodb in step 3. If you create the data folder as per the intructions in step 3, then you need to specify the path of that folder using --dbpath while running the mongodb's server ie. mongod in command prompt 1.
*If you want to skip entering --dbpath, only thing that you need to do is create the data folder in Windows directory ie. "C:\data" directly instead of creating in "C:\mongodb-win32-x86_64-3.0.6\data" .