How to Install MongoDB on Ubuntu 18.04

0
504

What is MongoDB:

MongoDB is one of the most popular and best known NoSQL database managers. Mainly, it is used for applications where you can save data in formatted documents such as BSON. This means that instead of saving data in records such as SQL types, it saves it in documents. 

In NoSQL type, database documents don’t have a defined schema. You might worry, that this will cause a messy database, but actually, it’s quite the opposite. In a system like this, “fields” and data are simplified, thus easier to manage and can be stored faster.

Moreover, MongoDB is familiar in environments for massive scalability. With MongoDB, you can quickly perform replication techniques that allow the scalability of the data. So any application that requires storing semi-structured data can use MongoDB.

Constructional Casts of MongoDB:

1. Data Model

Data is stored in the form of BSON -Binary encoded JSON documents which bears a rich collection of types. Fields in BSON document fields may contain an arrangement of values or embedded documents. Here, the database construct is a set of related collections. Every database has a distinct lay of data files and can have a huge number of collections. A MongoDB deployment may hold many databases.

What is a ‘document’ in Mongo DB?

A mono record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The field values may include other documents, arrays, and arrays of documents. This is a major variation from RDBMS systems where each field must have only one value.

2. GridFS

A designation for gathering and retrieving files that exceed the BSON-document size limit of 16MB.

GridFS divides a file into parts, and stores each part as a separate document rather than store in a single document. It utilizes two collections to store files. One of them stores the file chunks, and the other stores file metadata.

When we arise a question a GridFS store for a file, the client reassembles the chunks as needed. We can access information from any random section of files. This attribute is what generally permits for “skipping” into the middle of a video or audio file.

3. Sharding

Database systems with large data lay and high throughput applications can challenge the capacity of a single server in multiple ways such as:

High query rates situate stress on the CPU capacity of the server.

Larger data lays exceed the storage capacity of a machine.

When the system RAM size is smaller than dataset size then it will stress the I/O capacity of disk drives.

To denote these scale problems, database systems have two basic approaches:

  1. Vertical Scaling
  2. Sharding or Horizontal Scaling.

4. Data partitioning

MongoDB allocates data at the collection level. Sharding segregations a collection’s data by the shared key.

What is a shard key?

It is an indexed field or an indexed compound field that subsists in every document in the collection. MongoDB splits the shard key values into chunks and allocates the chunks evenly across the shards. To split the shard key values into chunks, MongoDB utilizes either range based partitioning or hash-based partitioning.

5. Aggregation

Operation is to process data records and give evaluated results. Apart from queries, aggregation operations in MongoDB utilize collections of documents as input and give results in the form of one or more documents. MapReduce is a tool used for aggregating data.

6. Indexes

These are special data structures that gather a little portion of the collection’s data set in an easy to cross form. It gathers the value of the desired field or set of fields, ordered by the value of the field.

The ordering of the index entries bears efficient equality matches and range-based query operations. Moreover, MongoDB can give arranged results by using the ordering in the index.

7. Replication

It gives redundancy and enhances data availability. With several copies of data on various database servers, replication protects a database from the loss of a single server and allows for recovery from hardware failure and service intrusion.

Install MongoDB on Ubuntu 18.04

Although MongoDB is a well-known application, it is not in the official Ubuntu repositories so you will have to add it manually. However, this is a huge advantage because it makes the installation and application updates easier. First, we have to connect to our server using SSH:

ssh [email protected]

If you are using Ubuntu 18.04, open the terminal and add the PGP key from the MongoDB repository to avoid compromising downloaded packages:

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

After that, you can add the MongoDB repository without any problem. To do it, run this command:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Next, refresh the APT command to synchronize all repositories.

sudo apt update

Next, install MongoDB using APT:

sudo apt-get install -y mongodb
sudo apt install mongodb-org

At the end of the installation, enable and start the MongoDB service. With this, you will be able to start using it.

sudo systemctl enable mongodb
sudo systemctl start mongodb

Finally, check the service status.

sudo systemctl status mongodb

Now you know how to install MongoDB on Ubuntu, and it is ready to be used.

We hope the above article helps to install the MongoDB on Ubuntu. For more information, like us on social media such as Facebook and Twitter. For video tutorials, subscribe to our YouTube channel “ServerCake India”.

LEAVE A REPLY

Please enter your comment!
Please enter your name here