Databases and Difference between MongoDB and MySQL

“Every day is a chance to begin again. Don’t focus on the failures of yesterday, start today with positive thoughts and expectations.” — Catherine Pulsifer

It kept on buzzing around my mind that What is the actual need for databases and the differences between the most popular used databases.

Let’s start from the beginning…

What is Data?

Data are characteristics or information, usually numerical, that are collected through observation. Data as a general concept refers to the fact that some existing information or knowledge is represented or coded in some form suitable for better usage or processing.

These data are random information. To organize them, we need a database management system(DBMS). A database can be defined as an organized collection of structured information, or data, typically stored electronically in a computer system. A database is usually controlled by a database management system (DBMS). Together, the data and the DBMS, along with the applications that are associated with them, are referred to as a database system, often shortened to just a database.

One might be wondering that spreadsheets were also originally designed for one user, and their characteristics reflect that. So what's the need for Databases. The spreadsheet is great for a single user or a small number of users who don’t need to do a lot of incredibly complicated data manipulation. On the other hand, databases are designed to hold much larger collections of organized information — massive amounts, sometimes. Databases allow multiple users at the same time to quickly and securely access and query the data using highly complex logic and language. Thus, quick access and manipulation.

Types of Databases :

  • Hierarchical databases

MySQL Database

MySQL is an open-source relational database management system based on SQL. It was designed and optimized for web applications and can run on any platform. As new and different requirements emerged with the internet, MySQL became the platform of choice for web developers and web-based applications. Because it’s designed to process millions of queries and thousands of transactions, MySQL is a popular choice for e-commerce businesses that need to manage multiple money transfers. On-demand flexibility is the primary feature of MySQL.

MySQL is the DBMS behind some of the top websites and web-based applications in the world, including Airbnb, Uber, LinkedIn, Facebook, Twitter, and YouTube.

MongoDB Database

MongoDB is a NoSQL database that stores data as JSON-like documents. Documents store related information together and use the MongoDB query language (MQL) for access. Fields can vary from document to document — there is no need to declare the structure of documents to the system, as documents are self-describing. Optionally, schema validation can be used to enforce data governance controls over each collection.

Image source: Author
https://www.geeksforgeeks.org/mongodb-vs-mysql/?ref=rp
https://www.geeksforgeeks.org/mongodb-vs-mysql/?ref=rp

Both databases support a rich query language. MySQL uses a structured query language(SQL) whereas MongoDB uses MongoDB Query Language(MQL). Can you guess which one is faster?

MongoDB could handle more complex queries faster due mainly to its simpler schema at the sacrifice of data duplication meaning that a NoSQL database may contain large amounts of data duplicates. Although a schema directly migrated from the RDBMS could be used this would eliminate the advantage of MongoDB’s underlying data representation of subdocuments which allowed the use of fewer queries towards the database as tables were combined. Despite the performance gain which MongoDB had over MySQL in these complex queries when the benchmark modeled the MySQL query similar to the MongoDB complex query by using nested SELECTs MySQL performed best although at higher numbers of connections the two behaved similarly. The last type of query benchmarked which was the complex query containing two JOINS and a subquery showed the advantage MongoDB has over MySQL due to its use of subdocuments. This advantage comes at the cost of data duplication which causes an increase in the database size. If such queries are typical in an application then it is important to consider NoSQL databases as alternatives while taking into account the cost in storage and memory size resulting from the larger database size.

Is MongoDB better than MySQL?

Higher availability: Replication of data in MongoDB is a first-class citizen — groups of MongoDB nodes that hold the same data set are called replica sets. Replica sets enable high availability of data, with developers able to fine-tune their consistency requirements for even greater performance and availability.

Faster development with JSON document: Working with data as flexible JSON documents, rather than as rigid rows and columns, is proven to help developers move faster. Data are natural, can be structure in array or subdocument. They are flexible to work with. We can add new attributes when we need to, without having to alter a centralized database schema. Changing schema causes downtime or significant performance overhead in a relational database like MySQL. Documents make applications fastHaving all the data for an object in one place, makes it easier for developers to understand and optimize query performance.

Scale infinitely and cheap: Scaling MySQL requires purchasing a beefier server or implementing a complex sharding solution in the application. Sharding allows you to add additional instances to increase capacity when required. It is cost-effective, spreading the load on the database across multiple sets of commodity hardware.In MongoDB, a new shard can be added at anytime and will automatically begin migrating data. There are no changes to be made in the application.

Terminology in MySQL and MongoDB
{
title: 'Geeksforgeeks',
by: 'Harshit Gupta',
url: 'https://www.mongodb.com/',
type: 'NoSQL'
}

Data representation in MongoDB

+------------+--------------+----------------+
| Student_ID | StudentName | Student_credit |
+------------+--------------+----------------+
| 1 | Charles | 957 |
| 2 | Rohan | 930 |
| 3 | David | 932 |
| 4 | Ferdinand | 982 |
+------------+--------------+----------------+

That’s all in this blog. Thank you for giving your time in reading.

3rd year CSE student at IIITKALYANI , enthusiastic learner and explorer