Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
A Database Management System (DBMS) is a system software used to create, manage and work with databases. MongoDB is a non-relational database management system. Unlike SQL(Structured Query Language) databases based on tables, MongoDB is a document-based database.
This blog will look into the various comparative aspects of SQL and MongoDB. We will learn multiple commands in Mongo and their SQL analogies.
MongoDB is often an integral part of the Javascript web ecosystem, MERN, or MEAN stack.
You can learn more about MERN stack web development here!
An analogy to RDBM Systems:
In traditional Relational Database Management Systems, data is stored in databases with rows and columns tables.
Mongodbis a NOSQL DBMS. In NOSQL DBMS, information is stored in a BSON format. A BSON format is simply a binary version of JSON. Data is stored in the form of collections.
If we create a diagrammatic analogy between SQL tables and NOSQL collections, we would have the following analogy:
Comparison between NOSQL and SQL DBMS
In every NOSQL collection, BSON Documents exist with single data storages called fields, just like columns exist in rows in SQL tables.
Before we compare SQL terminology to MongoDB terminology, let us first understand some basic concepts of SQL and MongoDB.
Field
This is a name and value pair.
Document
A group of fields is called a document.
Collection
A group of documents clubbed together, is called a collection.
Database
A physical container to keep multiple collections is called a database.
Now, let us see how these MongoDB concepts match up with SQL terminology.
SQL Terminology
MongoDB Terms
Database
Database
Table
Collection
Row
Document
Column
Field
Index
Index
Primary Key
Primary Key
Aggregation
Aggregation Pipeline
SELECT INTO NEW_TABLE
$out
MERGE INTO TABLE
$merge
table joins
$lookup, embedded document
As discussed in the first table, a field is the smallest part of a MongoDB, just like a column is the smallest part of a SQL table. Like columns clubbed together form rows and rows form tables, they are analogous to collections and documents.
Another important analogy that needs to be discussed here is that of the primary key. In SQL systems we can assign any unique column as the primary key. In MongoDB every collection has an _id field, which is automatically taken as the primary key.
Mapping SQL Commands to MongoDB
For learning the difference between SQL and MongoDB we will take an example. Let us assume a table called Demo in SQL. For the analogy, let us assume a collection called Demo in MongoDB which contains documents of the following type:
1. What is the analogy between SQL and MongoDB with regards to aggregation? Aggregation in DBMS refers to grouping two or more entities together in order to make a new, more meaningful new entity. MongoDB offers an aggregation pipeline just like SQL offers aggregation commands.
2. What are regex commands in MongoDB? Regex commands provide the ability to search for patterns in queries and requests. Examples of Regex commands are:
This blog looked into the various comparative aspects of SQL and MongoDB, a NOSQL Database Management System. If you were comfortable with SQL systems, you would now be comfortable working with MongoDB systems.
Now that you have learned about the differences between MongoDB and SQL, continue your backend development journey by following this link! You can also explore other blogs related to web technologies here.