They both conveniently start with M so whether it is MEAN or MERN, I suppose that the M could stand for both. I’ve used both databases extensively for a while and wanted to compare the two. So the ultimate question I suppose is… which one is better? Mongo or MySQL. Would MySQL be better off with the No than the My?
The answer I have to say is… it depends on what you’re doing.
Personally I like working with MongoDB more because I like coding in Javascript. When working with MongoDB in my projects, it feels like you do not necessarily have to learn a whole new syntax to make MongoDB queries. Also there is a big convenience in forgoing relational databases and using container databases (a document model being the container to be more clear). MongoDB uses nesting in order to set up relationships between data sets so the tree like database structure makes it very easy to grasp and understand the flow of information. The simplicity of the database in addition to easy query commands that can be chained together to run with an ‘.exec’ command makes MongoDB very easy to learn, use, and it is very effective.
As a result, I recommend MongoDB but ONLY for small, medium-size projects. What determines the size of a project you ask? Well I would say that size is synonymous with complexity. The more RELATIONSHIPS you need among your data tables, the more power and flexibility you need. The tree-like nested design of MongoDB which makes MongoDB easy to learn and use actually becomes a drawback once your application grows in complexity and is in need of a more powerful, dynamic, and flexible database.
To explain RELATIONSHIPS better to those who need a more visual example, suppose you have holiday decorations for Easter, Halloween, and Christmas. MongoDB can be seen as a container database in which you would store your decorations accordingly in a box for Easter, another box for Halloween, and the third box for Christmas. When Halloween comes around and you need to pull out all the Halloween decorations, it is very convenient to find all the items in one location. That is what makes MongoDB so easy to set up and use.
However, suppose that you receive new holiday tablecloths for your decorations and need to replace the ones you already have. It would be tedious for you to sort through each box and pull out the tablecloth and replace the item one by one.
MySQL makes it so that whenever you need to replace items for your decorations, you can do it all in one place. What MySQL does is get one giant box, throw all the content of the three holidays boxes in there, sorts through all the material, and pulls out the tablecloths you need to replace. You give instructions on how MySQL throws the contents into the one giant box (called JOINS in MySQL) and you are able to make adjustments accordingly in one place.
That is what is meant by RELATIONAL database. MySQL sets up flexible and customizable relationships between data tables (or holiday decoration boxes) so that the user does not have to go through separate data tables in order to make data adjustments.
MySQL is definitely the database you need to use for complex applications like business support systems for enterprises. Although MongoDB is effective for a group of developers the size of one to ten people, if the organization has dozens of developers who need to set up and make their own data without having to depend too much on others, then MySQL makes this possible. However, because MySQL is more powerful, there is a significantly higher learning curve than MongoDB. MySQL has its own syntax and you need to approach it as if you are learning a completely new programming language (because it is).
As a result, both MongoDB and MySQL has its pros and cons. Both are very popular and well supported by the tech community so learning either one would not be a bad idea.
For absolute beginners though, I recommend using MongoDB first so that beginners can focus more on learning the art of coding rather than being bogged down by additional complexity that can be learned later. It was painful for me to learn MySQL at the same time as learning web development. I realize now it was certainly not something I had to learn at the very start of my programming journey.
However, for more experienced people who are very familiar with HTML, CSS, Javascript, and making API requests, then I would recommend learning MySQL over MongoDB as MySQL would be able to do everything that MongoDB can do and offer more powerful capabilities. Also I think there are more jobs out there that require knowing MySQL over MongoDB.