How to setup Mongodb on Ubuntu!

Step by step Mongodb setup.

Intro

NoSQL databases (aka "not only SQL") are non tabular, and store data differently than relational tables. NoSQL databases come in a variety of types based on their data model. The main types are document, key-value, wide-column, and graph. They provide flexible schemas and scale easily with large amounts of data and high user loads. Click for more details.

Requirements

We need a machine with Ubuntu 16.04 installed a non-root user with sudo authority in order to have Mongodb working in your hand.

Import Repository

Import the public key used by the package management system.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

Output;

gpg: Total number processed: 1
gpg: imported: 1  (RSA: 1)

To add the list;

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

Update before installation;

sudo apt-get update

Download

sudo apt-get install -y mongodb-org

Starting Mongodb and Checking the Status

To start;

sudo systemctl start mongod

To status check;

sudo systemctl status mongod

When you execute the last command, you need to see green "Active: active (running)" message.

Starting Mongodb service on Boot-up

sudo systemctl enable mongod

Test

Let's test our newly created mongodb.

$ mongo --eval 'db.runCommand({ connectionStatus: 1 })'

Response;

MongoDB shell version: 3.2.21
connecting to: test
{
	"authInfo" : {
		"authenticatedUsers" : [ ],
		"authenticatedUserRoles" : [ ]
	},
	"ok" : 1
}

If you see the "ok": 1, 👍 Everything working normally.

The End

We currently have a fully working Mongodb installation in our operating system. If you wish, you can take a look at official documents.

Comments