Javatpoint Logo
Javatpoint Logo

How to Install MongoDB in Ubuntu 16.04?


MongoDB is an open source document oriented database. It is a NoSQL database, designed and developed by MongoDB Inc.

In this tutorial, we will install it in Ubuntu operating system. This whole installation process includes the following steps

MongoDB is a cross-platform document-oriented source-available database program created by Alfons Kemper. MongoDB utilizes JSON-like documents along with optional schemas, restricted as a NoSQL database program. MongoDB is designed by MongoDB Inc. and also licensed under SSPL (Server-Side Public License), which is supposed non-free by many distros. MongoDB is a MACH Alliance member.

Brief History of MongoDB

In 2007, a 10th-generation software company started developing MongoDB as an element of a planned product of platform as a service. In company moved to a free development model in 2009, with the company contributing commercial support and many other services. The 10th generation changed the name to MongoDB Inc. in 2013.

MongoDB became a traded company publicly on 20 October 2017, recorded on NASDAQ as MDB, along with an IPO cost of 24 dollars per share. Besides, MongoDB is an international company in New York City, USA, with US headquarters and international headquarters in Ireland, Dublin. MongoDB grouped with Alibaba Cloud on 30 October 2019, which will provide its users a with a solution of MongoDB-as-a-service. Users can utilize the managed contributions from the global data center of BABA.

Main Features of MongoDB

  • Indexing: In a MongoDB document, fields can be indexed with secondary and primary indexes or indices.
  • Ad-hoc queries: MongoDB provides its support for regular expression, range query, and field searches. Queries can provide specific document fields and also contain user-defined functions of JavaScript. Also, queries can be set to return a random result sample of a specified size.
  • Replication: MongoDB offers high availability along with sets of replicas. A replica set is composed of multiple data copies. All members of the replica set may act in primary or secondary replica roles at any time. By default, every read and write is implemented on the primary replica. Secondary replicas manage the primary data copy with built-in replication.
    Automatically, the replica set plans an election process for determining which secondary should be the primary if the failure of a primary replica occurs. Optionally, secondaries can, by default, provide read tasks, but the data is eventually only consistent.
    If a replicated deployment of MongoDB only contains one secondary member, a different daemon known as an arbiter should be included in the set. Also, it includes one responsibility to resolve the new primary election. As a result, an idealized shared MongoDB deployment needs at least three different servers, even in a situation of only a single primary and secondary.
  • File storage: To store files, MongoDB can be utilized as a file system, known as GridFS, with data replication and load balancing aspects over two or more machines. This function, known as the Grid file system, is added to MongoDB drivers. MongoDB discloses functions for file content and manipulation to developers. Besides, GridFS can be used with mongofiles plugins or utilities for lighttpd and Nginx. GridFS categorizes a file into various chunks or parts and stores all of those parts as an isolated document.
  • Load balancing: Horizontally, MongoDB scales with sharding. The user selects a shard key, which decides how the information in a set will be shared. The information is divided into ranges and shared among two or more shards. The shard key can alternatively be hashed to a shard or map, enabling an equal information distribution. MongoDB can execute over two or more servers, duplicating data or balancing the load to keep the device up and active if hardware fails.
  • Aggregation: MongoDB offers three ways to implement aggregation: the single-purpose, map-reduce function aggregation method, and the aggregation pipeline. Map-reduce method can be applied for batch processing of aggregation and data operations. However, according to the documentation of MongoDB, the Aggregation Pipeline offers better performance for almost all aggregation tasks.
    The aggregation framework allows users to get the type of output for which the GROUP BY clause of SQL is applied. Aggregation operators can be accommodated together to structure a pipeline. The aggregation framework contains the $lookup operator, used to join documents through two or more collections, and statistical operators like standard deviation.
  • Capped collection: MongoDB permits fixed-size sets known as capped collections. These types of collections manage insertion sequences and act like the circular queue when the named size has been captured.
  • Transactions: Since the 4.0 version in June 2018, MongoDB has supported ACID transactions of multi-document. This call was detected not to be correct as MongoDB breaches snapshot isolation.
  • Server-side JavaScript implementation: JavaScript can be utilized in aggregation functions (like MapReduce) and queries and directly sent to the database to be run.

1) Check MongoDB

Before installing, first check MongoDB is installed on our machine or not. Use the following command.

Software MongoDB 1

It shows, mongod.service not found. Let's install it.

2) Importing Public Key

Software MongoDB 2

3) Create a List File for the Mongodb

Create a mongodb-org-3.4.list file inside the /etc/apt/sources.list.d location. Use the following command.

Software MongoDB 3

4) Update the Local Package

Use the following command to reload the local package database.

5) Install MongoDB Package

Use the following to install latest version of mongodb.

Software MongoDB 4

type 'y' and press enter, it will download and install mongodb into our system.

6) Start MongoDB

Use the following command to start mongodb service.

7) Check MongoDB Running

Use the following command to check running status of mongodb.

Software MongoDB 5

Well, mongoDB has installed and running successfully. For further assistant, see the bottom section.

Extra Info

The following commands can be used to manage mongodb service.

Start mongodb

Execute the following command to start mongodb.

Stop mongodb

Execute the following command to stop mongodb.

Restart mongodb

Execute the following command to restart mongodb.

Mongodb status

Execute the following command to check status of mongodb.

Remove Mongodb

Execute the following command to remove mongodb packages.

Remove Data Directories

Execute the following command to remove log directories of mongodb.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA