What are the main differences between MongoDB and MySQL?
MySQL
MySQL is a popular, free-to-use, open-source relational database management system (RDBMS) developed by Oracle. As with other relational systems, MySQL stores data using tables and rows, enforces referential integrity, and uses structured query language (SQL) for data access. When users need to retrieve data from a MySQL database, they must construct an SQL query that joins multiple tables together to create the view on the data they require.
Database schemas and data models need to be defined ahead of time, and data must match this schema to be stored in the database. This rigid approach to storing data offers some degree of safety, but trades this for flexibility. If a new type or format of data needs to be stored in the database, schema migration must occur, which can become complex and expensive as the size of the database grows.
MongoDB
MongoDB is also free to use and open source; however, its design principles differ from traditional relational systems. Often referred to as a non-relational or NoSQL database, MongoDB adopts a significantly different approach to storing data, representing information as a series of JSON-like documents (actually stored as binary JSON, or BSON), as opposed to the tables and rows of relational systems.
In MongoDB, documents consist of a series of key-value pairs of varying types, including arrays and nested documents; however, the primary difference is that the structure of the key-value pairs in a given collection can vary from document to document. This more flexible approach is possible because documents are self-describing.
