Introduction to NoSQL database and MongoDB
By: Aayesha Shrestha
Tags: Mongodb, NoSQL, Database

What is the first thing you do after you wake up? If you ask me, I almost immediately turn on my phone to see if there are any messages and notifications from social media. Social media has become a huge part of my daily routine. And I think it’s not just me. Most of us start our day by checking our mobile phones and end with the same, whether we’re texting someone, checking out some DIY videos on Facebook, uploading a new picture to Instagram, posting updates on Twitter or watching Netflix/YouTube.

Have you ever wondered about the amount of data that social media applications are generating? The numbers are huge as you might have imagined. According to this research, Facebook alone has 5.76 billion Likes everyday and 682 million tweets are sent out per day. Data is being generated every minute of every day without us even noticing it. And not just social media, we are producing an increasing amount of data with our mobile phones, smart TVs, machines, wearables and other IoT devices. With these things, data is getting bigger and more chaotic everyday.

A lot of these data generated today are unstructured, that means they cannot be so readily classified and fit into neat boxes (example: photos and graphic images, videos, streaming instrument data, web pages, PDF files, emails, blog entries, messaging and chats etc.). Though relational databases such as MySQL, Oracle and Microsoft SQL server have been in use since a long time, they are a poor fit when it comes to handling rapid processing and analyzing vast amounts of varied and unstructured data and also they cannot handle change in data structure. We need techniques to handle unstructured data and manage database change that are automated, efficient and easy to use.

Let’s take an example of an e-commerce site. Suppose you have a relational database with a Users table that has 5000 rows and three columns — Full Name, Email and Address. Now in your e-commerce site, you are building a recommendation system that recommends products to the customers based on their age. So you want to add a new column called ‘Age’. It can be quite difficult to add a column as you will need to update it for all existing data. When using a relational database, flexibility is a one of the major challenges and even a simple change like adding or replacing a column in a table might be a million dollar task.

Inserting data with a new column to SQL database

Here is where NoSQL databases stand out. They can handle these changes excellently.

NoSQL databases emerged to meet the need of evolving data and applications. They were developed to provide a kind of data storage that does not statically define how the data must be modeled and fully support agile development. They are schemaless and are suited for unstructured data.

Inserting data with new field in NoSQL database

Let’s understand a few things about NoSQL databases.

The first thing that comes to our mind when we hear NoSQL is that it is not SQL. Some say the term “NoSQL” stands for “non SQL” while others say it as “not only SQL” to emphasize that they may support SQL-like query languages. Either way, most agree that NoSQL databases provide a mechanism for storage and retrieval of data that is modeled in means other than tabular relations used in relational databases. These databases do not conform to the rigid row-column-table schema and are well suited for unstructured data. You can define a schema and later change it easily according to your project needs.

Distributed data across several servers rather than having a single machine with larger size limits network downtime and single point of failure in NoSQL databases, making them suitable for use in big data and real time applications.

Among various NoSQL databases, MongoDB is consistently ranked as the world’s most popular NoSQL database according to DB-engines.