Set up mongodb on ubuntu

Mongodb is one of the nosql databases that has been growing popular in recent times.
Today we are going to install install and setup mongodb cluster on ubuntu on localhost.
The steps are as follows:
1)Import the public key used by the package management system
sudo apt-key adv --keyserver   hkp:// --recv EA312927

2)Create a list file for MongoDB
For ubuntu 14:


For ubuntu 16:

3)Reload local package database.
sudo apt-get update

4)Install the MongoDB packages.
To install latest stable release
sudo apt-get install -y mongodb-org

5)For Ubuntu 16(xenial) users, this is an additional step:
sudo gedit /lib/systemd/system/mongod.service
Add the following contents:

6)Mongodb should be started automatically.To check if mongodb service is started run the following command:
service mongod status
To start the service manually run:
sudo service mongod start

7)The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account.
You can check all logs generated by mongodb at /var/log/mongodb/mongod.log.
To change default port or other configurations you can edit following file:
gedit /etc/mongod.conf

In the next tutorial we will be learning about setting connection of nodejs server with mongodb.
Till then enjoy your life as developer and happy coding.

Share post-
About Saurabh Mhatre 71 Articles
Currently working in web and hybrid application development