mongodb vs mysql
mongodb vs mysql

Hi Guys, Welcome to Proto Coders Point. In this article, we’ll know why to use MongoDB when we already have a language like SQL which is being used for so many years. Why MongoDB is faster than SQL and when to choose MongoDB over SQL.

SQL databases have always been used the most in the world of technologies and have been the primary source of data storage for so many years. Data in SQL databases are stored in a relational way so it is called relational databases. In this modern world, we prefer to use non-relational databases which make the work so much easier and non-hectic.

What is the difference between MongoDB and MySQL?

As you might be knowing that, MongoDB is completely an open-source database which is been developed by MongoDB, Inc. MongoDB stores data in JSON format documents that vary in structure. It is a popular NoSQL database whereas,

And as I said in the above sentence, MySQL is one of the popular relational database management systems (i.e. RDBMS) that is developed, distributed, and supported by Oracle Corporation.

The difference between MongoDB & MySQL Databases is the way they handle data.

MySQL vs MongoDB

In MySQL, you’re only allowed to store types like int, text, and a few others in fields. (flat data)

In MongoDB, you can store rich data structures with sub-fields being objects as well.

the structure has to be pre-defined in MySQL. MUST pre-define the tables and structures.

With MongoDB, you can literally throw whatever you want into the collection and it’ll store it.

To create a connection between the MongoDB database and the express.js server, we use a JavaScript Object-oriented library called Mongoose. It lets you structure and writes queries, way simpler!

difference between mongodb and mysql

Why mongodb is better than SQL as your data storage

Let’s take a scenario to understand How fast MongoDB works instead of SQL.

Imagine you’re a freelancer and you have got a project!

You are asked to make a brand new social media platform.

Your client says:

“The site needs to be fast! We’re going global”,

“We also need comments and reply feature”,

“Don’t forget about likes”,

“Oh, rating for the user profile”,

“We need the section of a recent post”,

“And make sure we have a really easy way to tag people”,

You’re thinking of all these features!

In SQL, it’s going to take lots of tables and columns to structure the data, and also it needs to be fast. How can we make data response faster? What if we can do all these things in a simpler way and make it fast?

Instead of designing it with tables, we can use documents. MongoDB helps us to do this with its document model. with MongoDB you can take care of almost all the features.

Simply, you can do something like this:

So in MongoDB data is been stored in JSON form, i.e. in key-value pair.

{
"_id": "e194jsd784yfd64hd8ahf"
"name": "Shruti Panjwani",
"bio": "I am freelance full stack developer",
"posts": [
{"post": "This is my first post"},
{"post": "This is my second post"},
],
"company": "Coders Troop",
"likes": [38, 18],
}

That is why use mongodb over sql. Did you learn something new and interesting today? If yes, Share it with your friends 🙂 Thank you.