Sunday 27 March 2016

Install Mongodb on Windows


Please follow below steps to install mongodb on windows :

1) Download latest version of mongodb from https://www.mongodb.org/downloads#production


2) Run the .msi file , Accept the agreement & install the mongodb on your machine.

3) After successful completion of installation you will find "MongoDB" folder under "C:\Program Files"

4) Go to "C:\Program Files\MongoDB\Server\3.0\bin" path. Here you will find multiple application files. We are going to see use of each application as we move further :


  • mongod : Its a server component. mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations. It supports different options like :
    • --help : returns infomation about options and use of mongod
    • --version : returns mongod release number
    • --config <filename> , -f <filename> : specifies configuration file for runtime configuration option.
    • --quiet : runs mongnd in quite mode that limits the no of output.

  • mongo : Its a client component. mongo is an interactive JavaScript shell interface to MongoDB, which provides a powerful interface for systems administrators as well as a way for developers to test queries and operations directly with the database. It supports different options like 
    • --npdb : prevents shell to connect default connection with db. Post connection you can connect to database by creating object as conn = new Mongo(); db = conn.getDB("myDatabase");
    • --host <hostname> : used to connect to specific host.
    • --version : returns mongo release number.
    • <db address > : for ex : mongo 127.0.0.1/test
    • <js file> : specify the javascript file to run and exit.
5) Add path to environment variable.  Right click on "My Computer" -> Properties -> "Advanced System settings" -> "Environment Variable" -> select "Path" in system variables -> Edit -> Append this (;C:\Program Files\MongoDB\Server\3.0\bin;) path to variable value -> Apply / Ok the changes.









6) Run the command propt. To start the mongodb server , Run "mongod" : This will open the database so that we can connect to it.


This this window open. It will keep listening for database connection on particular port (27017 in this case). Log will also get append in this screen as client runs the command.


7) To connect to server as client, Open another window of command propt -> run "mongo". It will get connected to default test database.


Use "db" command to check you have successfully connected.

You can also see additional logs on server (mongod) window :



To exit from client connection , use either "exit" command or "ctrl + c" 
To shutdown the mongod connection use "ctrl + c". It will also kill all the client connection.

Basic Mongodb commands ... To be continued...




No comments:

Post a Comment