DEV Community

Cover image for MongoDB - From a Noob's Perspective
Miles Ager
Miles Ager

Posted on • Updated on

MongoDB - From a Noob's Perspective

Intro to MongoDB

Developed in 2007, the name MongoDB is derived from combining the words humongous and Database. It was developed by the internet advertising company DoubleClick as a tool to help handle the problems they were experiencing with scalability and speed due to increased internet traffic.

As someone with a lot of background using the JavaScript coding language, but a noob with database management systems, I was excited to learn that MongoDB stores data in a JSON-like format. This means that in order to manipulate or view the data, the commands and syntax used are almost identical to the function expressions, as well as datatypes we see in JavaScript. Additionally, Information is organized within a database using a prototype based structure that is practically identical to the patterns of inheritance we see within JavaScript.

Simplicity

Up until this point, my only experience with database management systems was mySQL. With mySQL, I was able to develop an understanding of the multitude of SQL commands as well as the different ways these commands can interact in order to produce the logic within a query. Unlike MySQL, which compartmentalizes it's data within columns inside of tables, MongoDB stores values within documents, that are organized into collections within the database. This particular method for data storage seen in MongoDB is unstructured. This means one can simply add a document that contains values for both the username collection and age collection without having to specify any specific relationships the new document has with other documents that also contain those collections. MySQL on the other hand, is a relational database management system that requires one to follow the specific table column value schema already present within the database in order to view or manipulate the desired data effectively.

Image description
Google DBMS Trends for MySQL vs. MongoDB

User-Friendly Features

MongoDB also has several user-friendly features that aren't present in MySQL. This is likely one of the reasons why we are seeing a loss in popularity among MySQL users as seen in the chart above. MongoDB has a built in feature that automatically attaches a unique id to any new object. In contrast, MySQL needs the user to add a feature within each new table that generates a unique id for that row. Otherwise, if there are multiple rows that contain the same values in each column, one could experience the undesired outcome where multiple rows are returned instead of just one. It would be difficult to find an example where you wouldn't want a unique id for a row that likely represents a unique instance within your schema. MongoDB is able to lookup as well as manipulate its document based structure by binding the desired function expression to the desired collection within the database. In order to view or manipulating data in MySQL, the user must first understand the specific relations within their schema. This can get complicated with massive databases, and often leads to one having to write queries that chain several commands identifying the specific columns from within specific tables where they want to return/manipulate specific values. To add to the complexity of writing a query in MySQL, if the user should make a mistake in their query construction, the error provided is often generic. This leaves the user with no other option but to sort through the entire logic within their query without a point of reference. However, with MongoDB, incorrect syntax or use of function expressions, provides an error that usually details the exact point of reference where the logic failed.

Image description
Stack Overflow percent of questions related to MYSQL vs. MongoDB

Although I am biased because most of my experience is with the JavaScript coding language, I find that the difference in complexity seen in using MongoDB vs. MySQL is glaring. MySQL was released in the 1995, which gave Developers at DoubleClick ample time to learn from and improve upon MySQL. In my opinion, which is supported by the chart above indicating percent of stack overflow questions related to MySQL vs. MongoDB, MongoDB provides a less frustrating alternative to MySQL as a database management system.

Sources:

MongoDB Basics
What is MongoDB – Working and Features
MongoDB vs MySQL – Difference Between Them

Top comments (0)