DEV Community

Mohmed Ishak
Mohmed Ishak

Posted on • Updated on

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.

Top comments (6)

Collapse
 
thejuju profile image
Julien Gabriel

The choice doesn't depend on the tech you choose in back-end but only on use case. Even sometimes, you'll need to use both of them...
There is no place for a versus between 2 different DBMS types (one is SQL, second is NoSQL).
Definitely more interesting to talk about uses cases that leads to choose relational databases systems (mysql, mariadb, postgres, SQL) and/or non-relational databases systems (MongoDB and lots of others).

Collapse
 
ishakmohmed profile image
Mohmed Ishak • Edited

yeah, lol. That's what I wrote pretty much. 😊

Collapse
 
thejuju profile image
Julien Gabriel

Not really in my opinion, but nevermind 🤷‍♂️.

Thread Thread
 
ishakmohmed profile image
Mohmed Ishak

yeah let's not get hung up on this

Collapse
 
filatovv profile image
Yuri Filatov

It is very interesting to read your works

Collapse
 
ishakmohmed profile image
Mohmed Ishak

Thanks man. 😃👍