|
Flexibility
First of all, let’s talk about flexibility. For example, there will be many products in a mall, and these products all have their own unique attributes, such as TV screen size and screen resolution. efficiency, and air conditioners have attributes such as cooling type and outdoor unit noise. It is very difficult to put them into the product table, which adds extra work for programmers to design data tables, and MongoDB does not have Schema (schema, data model). It will seem very simple.
MongoDB’s flexibility is also reflected in unstructured and semi-structured data. MongoDB provides full-text indexing and also supports geolocation query and indexing. For example, a user wants to know where there are public restrooms within a five-kilometer radius. This is a "geographic range query." Then he searches for the nearest bike. Mobike uses MongoDB to complete such "distance sorting query".
Scalability
The data cannot be placed on one machine, so sharding is needed to put it on several machines. Sharding has been a native feature of MongoDB for many years and is efficiently integrated with other MongoDB features.
For example, a complex aggregation query in a sharded cluster will be automatically allocated to multiple nodes for running based on the Shard Key (shard key), and the computing tasks will be pushed down to the data nodes as much as possible. Finally, Aggregate the results of all nodes on one node. Sharding can also automatically migrate data between nodes to balance their data volume. At the same time, combined with MongoDB's replication (replica set) technology, data loss can be effectively avoided (during testing, it was found that mongo will automatically discover all machine addresses of the replica set. When a Mongo is stopped, the connected server will not Error report)
Using sharded cluster structure distribution in MongoDB:
Disadvantages of MongoDB
-
As we all know, MongoDB takes up a lot of server memory
MongoDB is slightly less secure
too free and flexible files Data errors caused by storage format (...)
The size of a single document is limited to 16 M
For array types Data operations are not rich enough
When to choose MongoDB
After saying so much shit, the most important thing is when do we choose to use MongoDB
Log system, the log information generated during the operation of the system generally has many types, a large scope, and the content is relatively messy. These messy logs can be collected and managed through MongoDB
Geographical location storage. MongoDB supports geographical location, two-dimensional spatial index, and can store longitude and latitude, so two points can be quickly calculated. The distance between them, and other location information
The data scale is growing rapidly (such as the supplied attention information)
Need to ensure a highly available environment
File storage requirements
Other scenarios, such as game development, user information, equipment, points, etc. can be stored through MongoDB. In addition Logistics systems, social systems, and even Internet of Things systems
Types of databases
Having said so much, why do we put mysql and MongoDB together to compare and choose? It is because they are different types of databases. From the development of databases to the present, they are roughly divided into three types
RDBMS (relational database)
The first thing to mention must be the one we are most familiar with. The relational database to which mysql database belongs.
Features of relational databases:
For example, MySql, sql server Oracle, etc.
Features are represented through tables Establish association
basically use SQL language to manage the database
Nosql (non-relational database)
NoSql, also It is the database type of MongoDB, originating from a Meetup held in San Francisco in 2009, where a description of NoSql technology appeared: open source, distributed, non relational databases
Characteristics of non-relational databases:
There is no concept of rows and columns and the json class is used to store data
A collection is equivalent to "Table", document is equivalent to "row"
Friction between normalization and non-standardization.
Standardization limits innovation, non-standard words cannot be unified
NoSql was interpreted as Non-Relational when it was first proposed, and there is also No-sql means, but with the rapid development in recent years, SQL has gradually been used in a wider range of fields. Therefore, SQL is no longer an exclusive feature of RDBMS. SQL capabilities have also been introduced in the NoSql technology system, thus evolving The concept of Not-Only-SQL came out
Most NoSql technologies weaken the support for ACID semantics and complex related queries, adopt a simpler or more professional data model, and optimize the read and write paths, thus Can be exchanged for higher read and write performance
NewSql
According to the definition in the wiki
NewSQL is a class of modern relational database management systems that seek to provide the same scalable performance of NoSQL systems for online transaction processing ( OLTP) read-write workloads while still maintaining the ACID guarantees of a traditional database system.
NewSql can be said to be the product of the combination of traditional RDBMS and NoSql technology. Therefore, the typical NewSql technology can be understood as distributed It is a basic prerequisite for a relational database to support distributed transactions. NoSQL and NewSQL have a lot of overlap in their technology stacks, but there are obvious differences in whether they support relational models and how well they support complex transactions. Since I don’t know much about it, I won’t say much here.
Here I will simply introduce the types of databases. A storage technology that belongs to NoSql, NewSql, or RDBMS cannot be simply classified. After all, technology is constantly improving. For example, MySQL is now also Compatible with nosql features:
Some people may wonder why transactions are not mentioned when introducing the shortcomings of MongoDB. This is because in In the MongoDB 4.0 version in the summer of 2018, MongoDB introduced transaction functions and supported multi-document ACID features, such as using the mongo shell for transaction operations
Specific stress test data will be added later