MongoDB — Week 3

This week I started learning MongoDB and tried to understand what makes it so popular

Zafir Hasan
3 min readApr 16, 2019

What is MongoDB?

After finishing my chosen topics on ES6, I have moved onto learning MongoDB. MongoDB is a document-oriented, NoSQL database that has been quite popular lately due to some advantages it has over SQL databases. While learning adjacent topics in web development, I’ve heard the word “MongoDB” thrown around everywhere. While it’s not always great to follow the hype of a new and popular technology in web development, I really wanted to know what made this database so popular. Why are so many startups and businesses using this thing? And while MongoDB may or may not be popular in a few years, NoSQL databases will stick around in some form or another. So what does “NoSQL” and “document-oriented” even mean?

The first thing I learned about NoSQL is that the “No” is an abbreviation. It doesn’t mean there is no query language for the database, it stands for “not only SQL”, which is very different. Not only can these types of databases have highly structured data, but they also don’t have to. This is in contrast to relational databases that have been around for a long time, like MySQL, MariaDB, Oracle DB and others. Relational databases keep data in tables and have relational schemas which I as a programmer would have to create. These schemas describe the relationships between all the data. Therefore, relational databases can be highly structured and as complex as you’d like them. These relationships can be very important for complex data like tax information, for example. But NoSQL databases don’t need any of those schemas; you don’t have to describe the relationship between the data for your machine.

How Data is Stored in MongoDB

In MongoDB, data is stored in “collections”. Collections are the counterpart to tables in relational databases. Collections contain documents that are in a JSON like format (BSON). Documents are the counterpart to rows of data in SQL databases. A document will contain fields just like a table would in a relational database. However, the difference is that docs in MongoDB don’t have to be standardized. One doc could have 10 fields, the next 4; it doesn’t matter. Documents can also have fields with different data types. This is the big difference between relational and non-relational databases.

Example document

Advantages and Disadvantages of NoSQL

Because you don’t have to enforce complex schemas, MongoDB and other NoSQL databases like it are usually faster than relational databases. They are better for storing large amounts of data. They are horizontally scalable, which just means you can simply add more computers to handle bigger loads to the database. After learning all of this, it makes sense why NoSQL databases like MongoDB are making a resurgence nowadays. They’re easy to get up and running without making complicated schemas, they can store almost anything you’d like, they’re easily scalable for fast growing startups and businesses, and they can store very large amounts of data which is great for a world of ever increasing IoT devices and big data.

Of course, NoSQL databases have their downsides as well. If you have highly structured data to start with, you probably want to keep it in a relational database to enforce those constraints. In NoSQL databases, since there are no schemas in the database layer, you have to make sure your data makes sense in the application layer. If the integrity of the data is important, you also probably want to go with relational databases.

First Steps

After getting a good understanding of what MongoDB is, I decided to dive right in and start using it. I downloaded MongoDB and installed it on my computer along Mongo Compass which is the GUI that Mongo officially releases for their database. Following one the tutorials in my study, I was able to setup up the database on my computer, connect to it, and start saving and updating the database right from my terminal. This coming week will be spent learning some more basic operations and moving onto to using MongoDB in Node.js.

--

--