How to Install MongoDB on Ubuntu 16.04

mongodb-logo

In this tutorial we will show you how to install  mongoDB on ubuntu 16.04. MongoDB is an open source, document-oriented database. Instead of storing your data in tables and rows as you would with a relational database, in MongoDB you store JSON-like documents with dynamic schemas.

Some general points on MongoDB

Pros:

  • schema-less. If you have a flexible schema, this is ideal for a document store like MongoDB. This is difficult to implement in a performant manner in RDBMS
  • ease of scale-out. Scale reads by using replica sets. Scale writes by using sharding (auto balancing). Just fire up another machine and away you go. Adding more machines = adding more RAM over which to distribute your working set.
  • cost. Depends on which RDBMS of course, but MongoDB is free and can run on Linux, ideal for running on cheaper commodity kit.
  • you can choose what level of consistency you want depending on the value of the data (e.g. faster performance = fire and forget inserts to MongoDB, slower performance = wait til insert has been replicated to multiple nodes before returning)

Cons:

  • Data size in MongoDB is typically higher due to e.g. each document has field names stored it
  • less flexibity with querying (e.g. no JOINs)
  • no support for transactions – certain atomic operations are supported, at a single document level
  • at the moment Map/Reduce (e.g. to do aggregations/data analysis) is OK, but not blisteringly fast. So if that’s required, something like Hadoop may need to be added into the mix
  • less up to date information available/fast evolving product

Prerequisites

This article assumes you have at least basic knowledge of linux, know how to use the shell, root user or non-root user account with sudo privileges set up on your server.

Step 1 – Adding the MongoDB Repository

MongoDB already included in a Ubuntu package default repository, however we will install mongodb from official mongodb repository for more stable and updated verion.

Before we add repository, first we need import the key for the legitimate MongoDB repository using the following command

Add official mongoDB repository using these command below

Step 2 – Install MongoDB

Install mongoDB using apt-get , but before that we need to update local database list repository

Here the sample output in mongodb installation process

Step 3 – Configure MongoDB service

In ubuntu 16.06 we need to create a unit file describing the service. It’s used to determines the ubuntu system how to start or stop the service.

Create a configuration file named mongodb.service to setup unit file as shown below

Paste the following code below

Start mongodb process using command below

If your mongodb service successfully start it doesn’t return any output. You can check running status using command below

Sampe output from status command

Step 4 – Configure automatically starting MongoDB when boot

To make MongoDB automatically start when you boot the operating system, use the following command

The sample output should be like this

 

Congratulations,  you have successfully Install MongoDB on Ubuntu 16.04 Xenial

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *