Installation and Running Mongodb in Ubuntu

Installation and Running Mongodb

Hi readers

Let me show you how to do basic setup of mongodb quickly and easily.

Step 1

Choose your platform and download latest mongodb version from https://www.mongodb.com/download-center#community.

Extract it

Step 2

place your extracted folder to location of your choice lets say in home directory by doing

> cd mv <your mongodb folder name> /home/<your username>/<your mongodb folder name>

> cd bin

Step 3

Before starting mongodb you need to create a database directory for mongodb to store its collection data files. so do

> sudo mkdir -p /data/db

By default mongodb will search for this folder so we have created this
To give this folder writable permission you will do

> sudo chmod 777 -R /data/db
type your system password if asked

Step 4

To access mongodb commands everywhere from terminal you will do

> sudo cp * /usr/bin
type your system password if asked

Now Start mongodb service

> mongod

If it says "Waiting for connections" then your service is working fine. In other terminal tab / window do

> mongo

Now your mongodb is running and you are free to practice

Step 5

Running mongodb in fork mode

> sudo mongod --fork --logpath /var/log/mongodb.log

This will run mongodb service in background and you can connect to mongodb same as previous step

you can check mongodb logs by tailing file as

> tail -100f /var/log/mongodb.log

Step 6

Shutting down mongod process running in fork mode

> sudo mongod --shutdown

Hope this will help. Put your views / queries in comments.