Why MongoDB – 10 Reasons to Learn MongoDB for 2019

As we see in today’s world that most of the people are switching to MongoDB, there are still many who prefer to use a traditional relational database. Here, we will discuss why MongoDB should we choose? Like every coin has two faces, it has own benefits and limitations.

So, are you ready to explore the reasons to learn MongoDB?

Why MongoDB

Why MongoDB – 10 Reasons to Learn MongoDB for 2019

1. Why MongoDB?

As it is a NoSQL database, that’s why it has many reasons to learn MongoDB. These reasons have led the foundation to the worldwide popularity of MongoDB.

These are some reasons, of why MongoDB is popular.

  • Aggregation Framework
  • BSON Format
  • Sharding
  • Ad-hoc Query
  • Capped Collection
  • Indexing
  • File Storage
  • Replication
  • MongoDB Management Service (MMS)

Do you know How to Install MongoDB?

Why MongoDB should we learn

Top Reasons to learn MongoDB

i) Aggregation framework

We can use it in a very efficient manner by MongoDB. MapReduce can be used for batch processing of data and also for aggregation operations. MapReduce is nothing but a process, in which large datasets will process and generate results with the help of parallel and distributed algorithms on clusters.

It consists of two sets of operations in itself, they are: Map() and Reduce().

  • Map(): It performs operations like filtering the data and then performing sorting on that dataset.
  • Reduce(): It performs the operation of summarizing all the data after the map() operation.
Aggregation Framework in MongoDB

Aggregation Framework

ii) BSON format

It is JSON-like storage a format. BSON stands for Binary JSON. BSON is binary-encoded serialization of JSON like documents and MongoDB uses it, when to stores documents in collections. We can add data types like date and binary (JSON doesn’t support).

BSON format makes use of _id as a primary key over here. As stated that _id is being used as a primary key so it is having a unique value associated with itself called as ObjectId, which is either generated by application driver or MongoDB service. Below is an example to understand BSON format in a more better way:

Example-

{
"_id": ObjectId("12e6789f4b01d67d71da3211"),
"title": "Key features Of MongoDB",
"comments": [
...
]
}

Another advantage of using BSON format is that it enables to internally index and map document properties. As it is designed to be more efficient in size and speed, it increases the read/write throughput of MongoDB.

iii. Sharding

The major problem with any web/mobile application is scaling. To overcome this MongoDB has added sharding feature. It is a method in which, data is being distributed across multiple machines. Horizontal scalability is being provided with the sharding.

It is a complicated process and is done with the help of several shards. Each shard holds some part of data and functions as a separate database. Merging all the shards together forms a single logical database. Operations over here are being performed by query routers.

iv. Ad hoc queries

MongoDB supports range query, regular expression and many more types of searches. Queries include user-defined Javascript functions and it can also return specific fields from the documents. MongoDB can support ad hoc queries by using a unique query language or by indexing BSON documents.

Let’s see the difference between SQL SELECT query and resembling query:

E.g. Fetching all records of student table with student name like ABC.

  • SQL Statement – SELECT * FROM Students WHERE stud_name LIKE ‘%ABC%’;
  • MongoDB Query – db.Students.find({stud_name:/ABC/ });

v. Schema-Less

As it is a schema-less database(written in C++), it is much more flexible than the traditional database. Due to this, the data does not require much to set up for itself and reduced friction with OOP. If you want to save an object, then just serialize it to JSON and send it to MongoDB.

vi. Capped Collections

MongoDB supports capped collection, as it is having fixed size of collections in it. It maintains the insertion order. Once the limit is reached it starts behaving like a circular queue.

Example – Limiting our capped collection to 2MB

  • db.createCollection(’logs’, {capped: true, size: 2097152})

viii. Indexing

To improve the performance of searches indexes are being created. We can index any field in MongoDB document either primary or secondary.

Due to this reason, the database engine can efficiently resolve queries.

MongoDB Indexing

Indexing

viii. File Storage

MongoDB can also be used as a file storing system, which avoids load imbalance and also data replication. This function performed with the help of Grid File System, it is included in drivers which stores files.

Join DataFlair on Telegram
MongoDB File Storage

File Storage in MongoDB

ix. Replication

Replication is being provided by distributing data across different machines. It can have one primary node and more than one secondary nodes in it (replica set). This set acts like a master-slave. Here, a master can perform read and write and a slave copies data from a master as a backup only for a read operation.

Recommended Reading – How Projection in MongoDB Affects performance

MongoDB Replication

Replication

x. MongoDB Management Service (MMS)

MongoDB has a very powerful feature of MMS, due to which we can track our databases or machines and if needed can backup our data. It also tracks hardware metrics for managing the deployment. It provides a feature of custom alert, due to which we can discover issues before our MongoDB instance will affect.

MongoDB Management Service (MMS)

MongoDB Management Service (MMS)

2. Benefits of MongoDB

This is the second phase of Why MongoDB, advantages.

i. Load Balancing

If you are having a large set of data that you need to process then you can distribute the traffic amongst different machines with the help of load balancing. It helps the user in a way that you can continue your work even if one of the nodes/machines has stopped working due to some reason. The other nodes will keep the work in a continuation and your processing will not stop.

Load Balancing in MongoDB

Load Balancing

ii. Sharding

With the help of sharding, we can do horizontal scaling. Which is not possible with the help of a relational database. By using this method, we can distribute data across different machines. We make shards of the data that we are having with ourselves and then we try to make the processing task a bit easy.

Also, read – MongoDB limit () and Skip() method

Sharding in MongoDB

iii. Flexibility

It does not require data structures, that are unified in nature across all the objects that are being used. This makes it easier to use MongoDB. With the help of dynamic schema, it is very easy to use MongoDB.

Flexibility in MongoDB

Flexibility

iv. Speed

MongoDB can fast and easy process the data. But this is valid up to your data is in document format. We can say that it’s speed automatically increases as it is handling a large amount of unstructured data within seconds which feels like magic.

Follow this link to know more about Pros and Cons of MongoDB

MongoDB Benefits & Limitations

MongoDB Advantages and Disadvantages

4. Drawbacks/Limitations of MongoDB

This is the third phase of Why MongoDB, limitations.

i. Usage of Memory

As we know that MongoDB stores the key name along with every document so it is obvious that it will consume a large amount of memory. And as joins are also not possible so it becomes very difficult to work with duplicate data.

Usage of Memory in MongoDb

Usage of Memory

ii. No Joins

As we apply joins very easily in the relational database very easily, it is not possible to apply joins in MongoDB. So if you want to apply joins in it, then you will have to write many complex queries to perform join operation over here.

iii. Still Under Development

SQL was developed in the 1980s, and MongoDB just emerged in 2009. So due to this reason, MongoDB is not yet fully documented or tested and does not have total support from the experts of it.

Have a look – 16 Different types of Data types in MongoDB

5. Summary

So, after reading it, you can get an idea that why should we use it, what are its advantages and disadvantages.Besides, if you have any query, feel free to ask in the comment section below, we would love to help you.

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.