MongoDB vs. MySQL Differences
FAQs
Organizations of all sizes are adopting MongoDB, especially as a cloud database, because it enables them to build applications faster, handle highly diverse data types, and manage applications more efficiently at scale.
Development is simplified as MongoDB documents map naturally to modern, object-oriented programming languages. Using MongoDB removes the complex object-relational mapping (ORM) layer that translates objects in code to relational tables. MongoDB’s flexible data model also means that your database schema can evolve with business requirements. MySQL's rigid relational structure adds overhead to applications and slows developers down as they must adapt objects in code to a relational structure.
MongoDB can also be scaled within and across multiple distributed data centers, providing new levels of availability and scalability previously unachievable with relational databases like MySQL. As your deployments grow in terms of data volume and throughput, MongoDB scales easily with no downtime, and without changing your application. In contrast, achieving scale with MySQL often requires significant custom engineering work.
Database performance can vary widely depending on a number of factors—database design, application query patterns, and load on the database being just a few. Since MongoDB's document model stores related data together, it is often faster to retrieve a single document from MongoDB than to JOIN data across multiple tables in MySQL.
Many customers have evaluated and selected MongoDB over MySQL, both because of better performance at scale and for radical improvements to developer productivity.
For the reasons discussed above, MySQL and other relational databases have added support for JSON. However, simply adding a JSON data type does not bring the developer productivity benefits of a document database to MySQL. Why? Because MySQL’s approach can detract from developer productivity rather than improve it. Consider the following:
- Proprietary extensions to SQL: Querying and manipulating the contents of a JSON document requires the use of separate MySQL-specific SQL functions to access values, which will not be familiar to most developers. In addition, they are not supported or recognized by third-party SQL tools, such as BI platforms, data warehouse connectors, ETL and ESB pipelines, and more.
- How MongoDB is different: The MongoDB Query API is widely understood and adopted by industry-standard tools and connectors. Several mega-vendor database companies have even adopted the MongoDB API themselves.
- Legacy relational overhead: Even with JSON support, MySQL users are still tied to multiple layers of SQL or relational functionality to interact with JSON data—low-level JDBC/ODBC drivers and object relational mappers (ORMs). These layers impose high learning overhead. ORMs are also generally recognized as hard to optimize for performance and query efficiency—even for experienced relational developers. In addition, query optimization statistics for JSON data are more limited than those maintained for regular relational data types.
- How MongoDB is different: MongoDB drivers are implemented in the methods and functions that are idiomatic and natural to the programming languages used by developers.
- Complex data handling: When using JSON data, MySQL drivers do not have the capability to properly and precisely convert JSON into a useful native data type used by the application. This includes different types of numeric values (e.g., floating points, 64-bit integers, decimals), timestamps, and dates, or a Map or List in Java or a Dictionary or List in Python. Developers have to manually convert text-based JSON in their application, losing the ability to have fields that can take on multiple data types in different documents (polymorphism) and making the computation, sorting, and comparison of values difficult and error-prone.
- How MongoDB is different: Binary encoded JSON (BSON) used by MongoDB and its drivers supports advanced data types not supported by regular text-based JSON.
- No data governance: MySQL offers no native mechanism to validate the schema of JSON inserted or updated in the database, so developers need to add either application- or database-side functionality to apply governance controls against the data.
- How MongoDB is different: Schema validation, based on the JSON Schema IETF standard, allows developers and DBAs to define and enforce a prescribed schema structure for each MongoDB collection.
- Schema rigidity: MySQL users still need to define a schema for their regular relational data. If the schema is then modified to accommodate new application requirements, the table is locked for some operations until existing data is copied into the new schema, requiring applications to be quiesced during schema migration.
- How MongoDB is different: Developers and DBAs can combine the flexibility of a fully dynamic schema with the governance controls needed for some applications across all data stored in the database, not just subsets of it.
Get started with Atlas today
- 125+ regions worldwide
- Sample data sets
- Always-on authentication
- End-to-end encryption
- Command line tools