Sunday, June 29, 2014

Installation of Mongo DB | No-Sql mongo db installation steps on Linux | mongo db comands

Installation of Mongo DB for 64 bit Linux

 

What is Mongo DB ? 
---  MongoDB is a cross-platform document-oriented database that is defined as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster. Released under a combination of the GNU Affero General Public License and the Apache License, MongoDB is free and open-source software.
-----------------------------Steps for Mongo DB installation on Linux -----------------------------------------
Step 1 :-  Select the directory under which you want to install mongo db and check all the permission is assigned to your user for this directory or not. example :- read, write and execute.
Step 2 :-  Copy the installer file (mongodb-linux-x86_64-2.6.1.tar.gz ) for Linux into the directory created into step 1.
Step 3. Extract the files from the installer through tar command.
$ tar -zxvf mongodb-linux-x86_64-2.6.1.tar.gz
Step 4 :-  ensure the location of the binaries is set in the PATH variable.
export PATH=<mongodb-install-directory>:$PATH
Here replace <mongodb-install-directory> with the path of mongo-Db binaries.
Step 5 :-  Create some folder or directories under the mongo db home..
-  bin
-  data
-  log
Before starting installation, User needs to create some config file and folders for mongo db installation as below
-- for mongo db process , create /data/db directory. If we create any other directory than we need to specify DBPATH variable in mongo.cfg   (config file) to start mongo db process on the Linux box.
Example :-  
DBPATH= /opt/app/mongodb/mongodb-linux-x86_64-2.4.1/data/db
---- for logs
MONGOD.log=/opt/app/mongodb/mongodb-linux-x86_64-2.4.1/log
Step 6 :-   Also we have to create a mongod.config file under mongo db home directory that will have all the details and paths required to run mongod process on Linux. For example see below path
mongod.config=/opt/app/mongodb/mongodb-linux-x86_64-2.4.1/
Step 7 :-   To start mongo db, execute below command from the bin directory of mongo db
$ mongod --config /opt/app/mongodb/mongodb-linux-x86_64-2.4.1/mongod.config  --dbpath  /opt/app/mongodb/mongodb-linux-x86_64-2.4.1/data/db  &
Here "& " will run the mongo db process in background.

 

 Using Mongo DB:

       Since Mongo DB is a NoSQL DB, we can create our DB and use them from command prompt.
        Some Useful commands to work with Mongo DB:
       
        Using the Mongo Shell (mongo.exe), you can interact with Mongo DB from the command line.
         [INFORMATIONAL] Commands
         1) Get information on the host running  MongoDB
              db.adminCommand( { "hostInfo" : 1 } )
         2) Get Mongo DB version details:
             db.runCommand( { buildInfo: 1 } )
         3) Get Mongo DB status:
            db.runCommand( { serverStatus: 1, workingSet: 1 } )
         4) Get disk storage use by database:
            show dbs
         5) Select the ‘admin’ database, and query for a list of databases in the Mongo DB instance:
           use admin
           db.runCommand( { listDatabases: 1 } )

 
         6) Get stats about the ‘admin` database:

            db.stats()


         7) Get stats about the ‘blobs’ collection:
            db.blobs.stats()


         8) Counts the number of all documents in the collection “nodes”:
           db.runCommand( { count: 'nodes' } )


         9) Get information on users defined
           db.runCommand( { usersInfo: 1 } )



++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mongo DB Basic Commands
Apache Server installation steps
Mongo DB installation Steps
Apache Server 2.4.9
No-Sql DB Mongod
Apache HTTP Webserver