MongoDB Installation for Linux :

  • Download MongoDB for Linux from here.
    Download 64-bit version of Mongo, as 32-bit version is for development version which has limited amount of data. Always download stable release. To check whether it is stable or not try to find out second number of version or first number after point eg : 2.5 -> unstable and 2.6 -> stable.
  • After downloading mongo untar it with command :
    tar xvf <mongo-directory>.tgz
  • After untar, goto bin folder :
    $ cd mongo-directory/bin
  • Now we have to deal with mongo and mongod executables
    mongod  : – Connect to the database. It runs actual database server.
    mongo :- Shell to connect database.
  • By default mongodb puts it’s data in /data/db directory so create one for it in bin directory
    $ sudo mkdir -p /data/db
    $ sudo chmod -R 777 /data/db
  • Start server with
    $ ./mongod (inside bin folder)
  • Now open now tab in terminal ( Ctrl + Shift + t ). And in bin folder run
    ./mongo
    After running this you’ll see “>” prompt
To use or to create database in prompt type:
 > use demo ( it will automatically create demo database if it is not present )
 >db.names.insert( { "name" : "deepak" })
 >db.names.find()

It will show id, key and name. Viola! you are ready to use it.

Advertisements