This is the first post in the MongoDB series, where we will introduce the MongoDB database system and take a look at its features and installation methods.

Created 2020-03-05
Modified 2020-04-08

Other posts in this series:

This post is co-authored wih Classmate.


NoSQL database – MongoDB – First delivery

Purpose of technology

MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era, with the scalability and flexibility that you want with the querying and indexing that you need. It being a document database means it stores data in JSON-like documents.

The Mongo team believes this is the most natural way to think about data, which is (they claim) much more expressive and powerful than the traditional row/column model, since programmers think in objects.

How it works

MongoDB’s architecture can be summarized as follows:

For a more in-depth explanation, MongoDB offers a download to the MongoDB Architecture Guide with roughly ten pages worth of text.

_ Overview of MongoDB’s architecture_

Regarding usage, MongoDB comes with a really nice introduction along with JavaScript, Python, Java, C++ or C# code at our choice, which describes the steps necessary to make it work. Below we will describe a common workflow.

First, we must connect to a running MongoDB instance. Once the connection succeeds, we can access individual «collections», which we can think of as tables where collections of data is stored.

For instance, we could insert an arbitrary JSON document into the restaurants collection to store information about a restaurant.

At any other point in time, we can query these collections. The queries range from trivial, empty ones (which would retrieve all the documents and fields) to more rich and complex queries (for instance, using AND and OR operators, checking if data exists, and then looking for a value in a list).

MongoDB also supports the creation of indices, similar to those in other database systems. It allows for the creation of indices on any field or subfields.

In Mongo, the aggregation pipeline allows us to filter and analyze data based on a given set of criteria. For example, we could pull all the documents in the restaurants collection that have a category of Bakery using the $match operator. Then, we can group them by their star rating using the $group operator. Using the accumulator operator, $sum, we can see how many bakeries in our collection have each star rating.

Features

The features can be seen all over the place in their site, because it’s something they make a lot of emphasis on:

Corner in CAP theorem

MongoDB’s position in the CAP theorem (Consistency, Availability, Partition Tolerance) depends on the database and driver configurations, and the type of disaster.

Download

We will be using the apt-based installation.

The Community version can be downloaded by anyone through MongoDB Download Center, where one can choose the version, Operating System and Package.MongoDB also seems to be available in Ubuntu’s PPAs.

Installation

We will be using an Ubuntu-based system, with apt available. To install MongoDB, we open a terminal and run the following command:

apt install mongodb

After confirming that we do indeed want to install the package, we should be able to run the following command to verify that the installation was successful:

mongod --version

The output should be similar to the following:

db version v4.0.16
git version: 2a5433168a53044cb6b4fa8083e4cfd7ba142221
OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
	distmod: ubuntu1804
	distarch: x86_64
	target_arch: x86_64

References