MongoDB Vs. MySQL For Beginners

ishakmohmed

Mohmed Ishak

Posted on April 15, 2021

MongoDB Vs. MySQL For Beginners

Alt Text
If you're a beginner and you're confused which of these databases is the right one for you, you've come to the right place.

What's MySQL?

MySQL is a database with a SQL flavor, which means the data are separated to tables and rows. If a university uses MySQL to store data of students, the database will have a couple of tables (and each table will have row(s) of data) such as that for details of students (which stores the name and ID of students), table for all subjects, table for all courses, etc. In other words, the data are separated (for a good reason). These tables are connected with each other. Now, what if you want to get student X's name, ID, subjects taken, course, and so on? We need to query multiple tables to get his/her data so you'll write more codes which could go wrong. On the flip side, the data are very organized so if you need the list of all subjects, you only need to get the data from the table which stores all subjects.

What's MongoDB?

MongoDB is a database with a NoSQL flavor, which means here there are no relationships and no tables. MongoDB is a document based database which looks like JSON. Here's an example of MongoDB data in my note taking app.

_id: ObjectId(1234563xyz7l0a1215411160)
title: "Buy milk and eat pizza"
date: 2022-12-01T00:00:00.000+00:00
user_id: "60662a1c59b27b00159811c9"
name: "masteruser"
createdAt: 2021-04-02T06:40:59.830+00:00
updatedAt: 2021-04-02T09:55:01.660+00:00
__v: 0
Enter fullscreen mode Exit fullscreen mode

Here, if you wanna get title of a note, the name of author, and so on, you'll write lesser codes as all related data of a user are stored in a document. However, if you want to get all published dates, you need to query all the notes and extract the published date (you'll write more codes which could go wrong).

Which Database Is For You?

If you're an experienced developer, you know the answer to this: you need to pick the right DB depending on the use case, but since this post is targeted to beginners, here's my answer:

It depends on the language/framework you wanna use it with. If you wanna build a PHP web app, go for MySQL. These two are a solid combination and there are a lot of tutorials out there which will teach you how to connect your MySQL DB using PHP (and the community that use this combo is super large). With the same token, if you're planning to build a web app using Node.js, go for MongoDB, simply because it is much more popular for developers to use MongoDB with Node.js.

Later on, when you're pretty good at one of these databases, you should totally pick up the other one as it is not difficult to do so. You only need to know a few concepts to get any database up and running.

💖 💪 🙅 🚩
ishakmohmed
Mohmed Ishak

Posted on April 15, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

MongoDB Vs. MySQL For Beginners
mongodb MongoDB Vs. MySQL For Beginners

April 15, 2021