Friday, September 5, 2014

Downloading and installing MongoDB on windows

        Downloading and installing MongoDB is very simple and easy. Before you download MongoDB for your Windows you should know which version of Windows you’re using and to run MongoDB on your system also make sure that you’re using windows newer version than Windows XP.
    To check which version of Windows your using enter following command in terminal:-
wmic os get osarchitecture
It will show your windows architecture as shown in below image:-







Downloading and installing MongoDB involves following three steps:-
1.     Download zip file
2.     Extract the file
3.     Setup the environment 




1.     Download  zip file:

Go to http://www.mongodb.org/downloads link and download zip file.                   
.


 2.  Extract the file:
  ·  After downloading file make temporary folder name “temp” in C drive and extract all files in it. Then go to temp folder and rename the folder name from “mongodb-win32-x86_64-2008plus-2.6.4 .zip” to only “mongodb” and pest it outside the temp folder on c drive so it will be easy to navigate folder .

  ·  This is it! We done with installation. There is no installation process.



 3.  Setup the environment :
  ·   Before starting operation every time we have to make connection between client and server or setup the environment.
  ·   Let’s follow following steps:-
     3.1. Crate directory on c drive:
  · Now go to start menu à type “cmd” à right click on “cmd”àselect “Run with      administration” option. Now create directory “data” and “db” directory in “data”      using following commands:
           c:\>mkdir data
           c:\>cd data
           c:\data> mkdir db
           c:\data>cd db
           c:\data\db>
         · The reason behind making these directories is that mongodb will use this                  directories to store the data related to operations that we are going to perform          on mongo shell or at the client side.

         · By default mongodb consider “c:\data\db” path but we can create other than         this if we want to use different folder to store the data but after that we have           to explicitly specify the path of that folder using following command:
      --dbpath “c:\foldername\db”

            But if you’re setting up environment for the first time then you should go with“c:\data\db”.


3.2. Start Mongod service:
   ·    To run mongo shell “mongod” service should be up and running. Now come        out of “data” folder then “db” folder using “cd\” command

    · Now go such as cd mongodb->cd bin->mongod  as shown below.

    


   · If it’s showing port 27017 then our “mongod” service is successfully running!

3.3. Start mongo shell:
    ·  Now open new terminal and now just type path “mongodb\bin\mongo” as shown below.

    ·   It will show the mongo shell. Here we complete our connection setup.

Let’s Test the connection:
  •   By default mongo runs “test” database. Now to test the connection we will insert document in database. Just type following command:


db.message.insert({name:’me’,message:’My name is kaveri’}



  • Let’s retrieve the document that we have inserted use following command:

db.message.find( )


  • It is displaying the document that we have inserted.
  • We have established connection between “mongod” and “mongo” if shell performs both the operations successfully. The document will get stored into the “data” folder which we have created in beginning.
  • Type “exit” command to get exit from mongo. It will show “bye” message.