Comparative Analysis of MySQL and MongoDB: Features, Performance, and Practical Insights
The article compares MySQL’s relational tables with MongoDB’s schema‑free documents, detailing equivalent concepts, CRUD syntax, and benchmark results that show MongoDB achieving higher write and query throughput, easier schema evolution, and built‑in sharding, recommending it for new agile projects while suggesting MySQL remain viable for legacy systems.
This article compares MySQL (a relational database) and MongoDB (a document‑oriented NoSQL database) to help developers choose a storage solution for production environments.
Terminology mapping – The table below aligns MongoDB concepts with their MySQL equivalents:
MongoDB
MySQL
Database
Database
Collection
Table
Document
Row
Field
Column
Data storage format
In MySQL a student record is stored as a row in a table (SQL DDL required). Example schema columns: id, gmt_create, gmt_modified, student_number, last_name, first_name, full_name, gender, date_of_birth, register_time, grade.
In MongoDB the same data is stored as a JSON‑like document (BSON) without pre‑defining a table:
[
{
"_id" : "5a760bf9e1d51a18bebcf5e1",
"gmtCreate" : "2018-02-04 03:22:33.666",
"gmtModified" : "2021-02-04 17:02:03.888",
"studentNumber" : "123505666",
"lastName" : "白",
"firstName" : "敬亭",
"fullName" : "白敬亭",
"gender" : "M",
"dateOfBirth" : "1993-10-15",
"registerTime" : "2018-09-01 00:08:08.686",
"grade" : 1,
"_class" : "com.alibaba.xxx.xxx.StudentDO"
},
{
"_id" : "601cd6196b919e6b328d8888",
"gmtCreate" : "2021-02-05 13:22:33.778",
"gmtModified" : "2022-02-05 17:02:03.345",
"studentNumber" : "123505888",
"lastName" : "赵",
"firstName" : "今麦",
"fullName" : "赵今麦",
"gender" : "F",
"dateOfBirth" : "2002-9-29",
"registerTime" : "2021-09-01 08:08:08.225",
"grade" : 1,
"_class" : "com.alibaba.xxx.xxx.StudentDO"
}
]Basic CRUD syntax
Insert a student record:
INSERT INTO student (gmt_create, gmt_modified, student_number, last_name, fitst_name, full_name, gender, date_of_birth, register_time, grade) VALUES (now(), now(), "123505666", "白", "敬亭", "白敬亭", "M", "1993-10-15", "2018-09-01 08:08:08", 3); db.student.insert({
"gmtCreate" : "2018-02-04 03:22:33.666",
"gmtModified" : "2021-02-04 17:02:03.888",
"studentNumber" : "123505666",
"lastName" : "白",
"firstName" : "敬亭",
"fullName" : "白敬亭",
"gender" : "M",
"dateOfBirth" : "1993-10-15",
"registerTime" : "2018-09-01 00:08:08.686",
"grade" : 1
});Delete a record:
DELETE FROM student WHERE id = 888; db.student.deleteMany({ "_id" : "601cd6196b919e6b328d8888" });Update a record:
UPDATE student SET grade = 4 WHERE id = 888; db.student.update({ "_id" : "5a760bf9e1d51a18bebcf5e1" }, { $set : { "grade" : 4 } });Query a record:
SELECT * FROM student WHERE full_name = "赵今麦"; db.student.find({ "fullName" : "赵今麦" })Performance testing
Tests were run on a single 16‑core, 128 GB RAM, 1 TB SSD server. Results (average over multiple runs):
Concurrent writes – up to 1 000 000 inserts in 22.6 s (≈44 k QPS).
Concurrent indexed queries – up to 1 000 000 lookups in 8.3 s (≈120 k QPS).
Observations:
MongoDB enables rapid agile development because no schema changes are required.
Schema evolution (adding/removing fields) is trivial in MongoDB, while MySQL needs DDL, ticket approval, and mapper updates.
MongoDB’s document model naturally supports polymorphism and nested objects.
Indexing on nested fields or array elements is straightforward in MongoDB but difficult in MySQL.
Transactions are supported from MongoDB 4.0 onward, though they add overhead.
Horizontal scaling (sharding) is built‑in and easier to use than MySQL’s manual sharding.
Monitoring and alerting for MongoDB are less mature in the author’s environment.
Conclusion
The article concludes that MongoDB delivers higher write and query throughput on a single server and scales well with replication and sharding. For new projects requiring fast, agile development, MongoDB is recommended. Existing MySQL projects may stay with MySQL to avoid migration costs.
DaTaobao Tech
Official account of DaTaobao Technology
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.