Sunday, September 28, 2014

MongoDB: quick installation guide

Introduction


In this module, we will be demonstrating how to install mongodb for various OS.

Environment


1. Install MongoDB On Windows

To install the MongoDB on windows, first doownload the latest release of MongoDB from http://www.mongodb.org/downloads. Make sure you get correct version of MongoDB depending upon your windows version. To get your windows version open command prompt and execute following command.

32-bit versions of MongoDB only support databases smaller than 2GB and suitable only for testing and evaluation purposes.
Now extract your downloaded file to c:\ drive or any other location. Make sure name of the extracted folder is mongodb-win32-i386-[version] or mongodb-win32-x86_64-[version]. Here [version] is the version of MongoDB download.
Now open command prompt and run the following command


In case you have extracted the mondodb at different location, then go to that path by using command cd folder/dir and now run the above given process.
MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is c:\data\db. So you need to create this folder using the Command Prompt. Execute the following command sequence


If you have install the MongoDB at different location, then you need to specify any alternate path for \data\db by setting the path dbpath in mongod.exe. For the same issue following commands. In command prompt navigate to the bin directory present into the mongodb installation folder. Suppose my installation folder is D:\set up\mongodb.


This will show waiting for connections message on the console output indicates that the mongod.exe process is running successfully.
Now to run the mongodb you need to open another command prompt and issue the following command


This will show that mongodb is installed and run successfully. Next time when you run mongodb you need to issue only commands


2. Install MongoDB on Ubuntu

Run the following command to import the MongoDB public GPG Key:


Create a /etc/apt/sources.list.d/mongodb.list file using the following command.


Now issue the following command to update the repository:


Now install the MongoDB by using following command:


In the above installation 2.2.3 is currently released mongodb version. Make sure to install latest version always. Now mongodb is installed successfully.

Start MongoDB


Stop MongoDB


Restart MongoDB


To use mongodb run the following command


This will connect you to running mongod instance.

Help

To get list of commands type db.help() in mongodb client, this will give you list of commands as follows:


Statistics

To get stats about mongodb server type the command db.stats() in mongodb client, this will show the database
name, cumber of collection and documents in the database. Output the command is shown below:



No comments:

Post a Comment