Saturday 5 October 2013

Installation Process of MongoDB on Windows

Posted by Kanhaiya

This tutorial provides a method for installing and running the MongoDB server (i.e. mongod.exe) on the Microsoft Windows platform through the Command Prompt and outlines the process for setting up MongoDB as a Windows Service.

There are following steps to Install MongoDB on windows OS.

Step 1. Download MongoDB -
Download the MongoDB from the official MongoDB website. Pre built binary packages of MongoDb are available for both 32 bit and 64 bit. You can download it, and install.

Note: Always download the correct version of MongoDB for your Windows system. The 64-bit versions of MongoDB will not work with 32-bit Windows.
You can find the architecture of your version of Windows platform using the following command in the Command Prompt:
wmic os get osarchitecture

Step 2. Unzip MongoDB folder and creating directory -
Unzip it to your prefer location, for example : C:\mongodb\

Step 3. Set up the Environment -
Start the Command Prompt by selecting the Start Menu, then All Programs, then Accessories, then right click Command Prompt, and select Run as Administrator from the popup menu. In the Command Prompt, issue the following commands:

cd \
move C:\mongodb-win32-* C:\mongodb

Note: MongoDB is self-contained and does not have any other system dependencies. You can run MongoDB from any folder you choose. You may install MongoDB in any directory (e.g. D:\test\mongodb)

MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is C:\data\db. Create this folder using the Command Prompt. Issue the following command sequence:
md data
md data\db

Note: You may specify an alternate path for \data\db with the dbpath setting for mongod.exe, as in the following example:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data

If your path includes spaces, enclose the entire path in double quotations, for example:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"

Step 4. Start MongoDB -
To start MongoDB, execute from the Command Prompt:
C:\mongodb\bin\mongod.exe

This will start the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.

Note: Depending on the security level of your system, Windows will issue a Security Alert dialog box about blocking “some features” of C:\\mongodb\bin\mongod.exe from communicating on networks. All users should select Private Networks, such as my home or work network and click Allow access. For additional information on security and MongoDB, please read the Security Concepts page.

Connect to MongoDB using the mongo.exe shell. Open another Command Prompt and issue the following command:
C:\mongodb\bin\mongo.exe


Note: Executing the command start C:\mongodb\bin\mongo.exe will automatically start the mongo.exe shell in a separate Command Prompt window.

For show all Databases use this command-
show dbs;


The mongo.exe shell will connect to mongod.exe running on the localhost interface and port 27017 by default. At the mongo.exe prompt, issue the following two commands to insert a record in the test collection of the default test database and then retrieve that record:
db.test.save( { a: 1 } )
db.test.find()


Note: mongo and mongo Shell Methods is very helpful if you want to develop any applications using JAVA.

Step 5. MongoDB as a Windows Service -
Setup MongoDB as a Windows Service, so that the database will start automatically following each reboot cycle.

Configure the System
You should specify two options when running MongoDB as a Windows Service: a path for the log output (i.e. logpath) and a configuration file.
  1. Create a specific directory for MongoDB log files:
  2. md C:\mongodb\log
  3. Create a configuration file for the logpath option for MongoDB in the Command Prompt by issuing this command:
  4. echo logpath=C:\mongodb\log\mongo.log > C:\mongodb\mongod.cfg
While these optional steps are optional, creating a specific location for log files and using the configuration file are good practice.

Install and Run the MongoDB Service
Run all of the following commands in Command Prompt with “Administrative Privileges:”
  1. To install the MongoDB service:
  2. C:\mongodb\bin\mongod.exe --config C:\mongodb\mongod.cfg --install Modify the path to the mongod.cfg file as needed. For the --install option to succeed, you must specify a logpath setting or the --logpath run-time option.
  3. To run the MongoDB service:
  4. net start MongoDB

Stop or Remove the MongoDB Service
  1. To stop the MongoDB service:
  2. net stop MongoDB
  3. To remove the MongoDB service:
  4. C:\mongodb\bin\mongod.exe --remove
Step# 6: In additional, MongoDB come with a web admin interface listening on port 28017:-



2 comments:

  1. Replies
    1. any queries like inserts or update.. on mongodb are significantly faster than other relational database.
      for access huge amount of data is mongodb is better as compare to other..
      and some other features like document database, high performance & easy to use...

      Delete