In this page, we will begin with Document based Database called Mongodb which is quite popular among the developers worldwide. Mongodb is a document based NoSQL db. It has become quite popular over the recent years and many big clients and organizations are the major supporter of this database. It was initially launched in 2009 and is developed and distributed by 10gen organization. Its open source and is freely available for the developers to explore and learn the database.

MongoDb Setup and installation

MongoDb comes in 32/64 bit flavors for different OS platforms. You can get the installation from Mongodb site.
It is always preferred to install 64 bit flavour for better performance.

MongoDb Installation on Windows environment

Here are the steps of installtion Mongodb in Windows.
  1. Create a folder in C drive with mongo name.
  2. Click on Mongodb installer for windows.
  3. Continue to click next until you get the below screen
  4. MongoDB windows installer
    MongoDB windows installer

  5. Select Custom and provide the path for mongo folder created in step 1.
  6. MongoDB windows installation location
    MongoDB windows installation location

    With this mongodb is installed in your machine.
My installation path is C:\mongo\bin
MongoDB windows installer files
MongoDB windows installer files

Testing for bug

Next we need to do some certain configuration for mongodb. There is a small bug in the Mongodb windows installer which some of you might face while trying to run the service. In order to check for the bug open the command console and give the command as below:-
MongoDB windows installer bug
MongoDB windows installer bug

When you see this issue then you have to do certain configuration inorder to run mongodb. This configuration will try to resolve the bug and also set the system path to automatically pick up the command to run mongodb.
Configuring mongodb in Windows
  1. Create another folder called data inside installation folder.
  2. Inside bin folder create a startmong.bat file and open it with notepad application
  3. Copy the below command inside startmongo.bat file
    mongod --dbpath C:\mongo\data
  4. Now close the startmongo.bat file
  5. Open environment or system variables through properties
  6.  Windows environment  variable
    Windows environment variable

  7. Go to Path and edit it. Add the path to bin folder of mongodb installation.
  8.  Create Windows environment  variable for mongodb
    Create Windows environment variable for mongodb

  9. Click ok and close all the windows. With this we are done with configuration of the Mongodb on windows machine.

Running the MongoDb service
Mongodb has two components namely service and shell prompt to connect to the database. After the configuration has been done it eliminates the need to provide path to bin folder in the command prompt every time you want to run the mongodb . In order to run the mongodb service open the command prompt and provide the command startmongo. Once you execute startmongo you will get screen as below :-
Mongodb service startmongo
Mongodb service startmongo

The bug will be visible on the screen but it won't stop the service and service will run uninterrupted.

Opening shell prompt Open another command window and give command mongo and you will get screen as below :-
mongo shell

Now mongodb is fully installed and running successfully on windows machine.

MongoDb Installation on Ubuntu

MongoDb Installation on Ubuntu is very easy and doesn't have the complexity of windows machine. If you don't want to fall into too much complexity and want simple installation then follow the steps as mentioned below :-
  1. Run the below commands from terminal of Ubuntu
    $ sudo apt-get update
    $ sudo apt-get install mongodb install -y mongodb-org
  2. Start the mongod service by executing the commands as below :-
    $ sudo service mongod start
  3. Open another terminal window and execute command :-
    $ mongo
The above command would open the shell prompt which will connect to mongodb. Your mongodb installation is complete and ready to be used.