MongoDB
1.What is MongoDB?
MongoDB is a database management system designed for web applications and the Internet infrastructure. MongoDB is a NoSQL type database featuring cross-platform and distributed file storage. Mongo stores the data as a document, and the data structure is in the form of a key-value pair (key: value). The basic concepts in MongoDB are documents, collections, and databases. Use BSON (similar to JSON) as the data model structure, such as storing a user in mongoDB like this:
{
username:’123’,
password:’abc’
}
2.MongoDB’s features
MongoDB uses the above data model to store data, which can improve the literacy ability in the production environment. Of course, the throughput is greatly increased compared with sql. There is also easy to scale, automatic failover. Because MongoDB can fragment data sets, the pressure of data storage is spread across multiple servers. Automatic failover is the concept of replica set. MongoDB can detect whether the primary node is alive. When it is deactivated, it can automatically raise the secondary node as the primary node to achieve failover. The data model is object-oriented, so it can represent rich, hierarchical data structures. For example, in a blog system, you can put "comments" directly into the "article" document, instead of creating three tables like myqsl to describe such relationships.
To sum it up is:
2.1Document data type
The SQL type database is normalized, and the integrity and uniqueness of the data can be guaranteed by the primary key or foreign key constraint. Therefore, the SQL type database is often used for systems with high data integrity. MongoDB is not as good as SQL type database in this respect, and MongoDB does not have a fixed schema (Graph). Because MongoDB lacks some such constraints, it can make data storage data structure more flexible and storage faster.
2.2Instant query capability
MongoDB retains the ability of relational database instant queries, retaining the ability of the index (the underlying is based on the B tree). This takes advantage of the relational database, which does not have the above capabilities compared to the same type of NoSQL redis.
2.3Replication ability
MongoDB itself provides a replica set that distributes data across multiple machines for redundancy, with the goal of providing automatic failover and extended read capabilities.
2.4Speed and durability
MongoDB driver implements a write semantic fire and forget, that is, when the driver calls the write, it can immediately get the result of the return success (even if it is an error), so that the write speed is faster, of course, there will be some insecure. Sex, completely dependent on the network. MongoDB provides the concept of Journaling log. In fact, like mysql's bin-log log, when it needs to be inserted, it will write the record to the log first, and then complete the actual data operation, so if there is a power outage, the process is suddenly interrupted. It can guarantee that the data will not be wrong, and can be repaired by reading the Journaling log through the repair function.
2.5Data expansion
MongoDB uses fragmentation technology to extend the data. MongoDB can automatically slice and automatically transfer the data blocks in the fragment, so that the data stored in each server is the same size.
The following table is a comparison of relational data:
Relational Database | Non-relational database |
Database | Database |
table | set |
Row | document |
list | Field |
Table join | Embedded document |
Main key | Main key,mongo Automatically set the _id field to the primary key |