29 Dec 2013

How to Install MongoDB ?


To get started on MongoDB, lets setup the workstation to have it working with MongoDB. Lets understand simple steps to install MongoDB on my system.

Step 1: Download Installation

Download the latest distribution of MongoDb from their official website

Step 2: Unzip the distribution

Unzip the downloaded zip to any folder location, say D:/mongodb, let me refer this part as MDB_HOME from here on.

It is recommended to have MongoDB path set into windows environment path variable so that you can run the MongoDB commands (executables from MDB_HOME/bin folder) from any location. 

Step 3: Start mongodb server

To start mongodb server, simply navigate to the MDB_HOME/bin path from the command prompt and type in the below command in the command line

D:\mongodb\bin>mongod.exe -dbpath d:/data

Things to note here is that mongod.exe is the command that is used to start the mongodb server, however there is a required parameter without which the server would fail to start, i.e. -dbpath, this parameter signifies the location where mongo DB needs to store / refer all the data files that it would create while all db operations.

Note, that the folder data (as refered here) needs to be created before hand manually, before executing the command.

The result would be something similar to the screenshot as shown below

Figure 1: Start mongodb server using dbpath parameter

Step 4 (Optional): Create a configuration file for start up

Although the startup of the server can be done manually, it is preferred creating a configuration file and using that while start up. The configuration file could be a central location of maintaining different parameters that we want to configure. Although -dbpath is the only mandatory parameter but mongodb offers a large number of parameters that you can plan along with. I will cover another variable -logpath here in this article. -logpath variable is used to create all logs in a file rather than on the command line itself.

Lets create a file file MDB_HOME/bin/mongodb.config file with the below stated lines

##store data here

 ##all output go here

 ##log read and write operations


In this file i have declared the dbpath and logpath. Please note that all this folder structure needs to be created manually and be in place before you use them while starting your mongodb server.

Once you have created the file, you can simply use the following command in the command line to start the mongodb server

D:\mongodb\bin>mongod.exe -config mongodb.config

This would result in the below shown view on your commandline

Figure 2: Start mongodb server using configuration file

Step 5 : Connect to mongodb server

Once the mongodb server is up and running, lets do a simple test where we will try to connect to this database from another command line terminal. 

 It is actually very simple connecting to the mongodb server, we need to use a just the command "mongo"  form the command line at MDB_HOME/bin, refer figure 3 below

Figure 3: Connect to mangodb server
Thats it, we have now learned how to install mongodb, start the server and connect to the server, we will learn about creating a database (collection) in the next article.


Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.


Post a Comment


© 2013 NimbleGeek. All rights resevered. Designed by Templateism

Back To Top