当前位置:网站首页>Mongodb: I. what is mongodb? Advantages and disadvantages of mongodb
Mongodb: I. what is mongodb? Advantages and disadvantages of mongodb
2022-07-01 06:24:00 【Great masses】
The whole content of this article is MongoDB4.2 Version based .
List of articles
One 、MongoDB What is it? ?
MongoDB Is a scalable 、 Open source 、 Table structure freedom , from C++ Write a document oriented high-performance distributed database . It is more like a relational database (RDBMS) And non relational databases (NoSQL) Database between , Yes no relational database has the most functions 、 Most like a relational database, a non relational database .MongoDB The supporting data structure is very loose , Is similar to json Of bson Format , It can store complex data types .
1. MongoDB The concept of
For the sake of understanding , The following table shows Mysql And MongoDB Compare ,Mysql The table in corresponds to MongoDB Set concept in ,Mysql The line in corresponds to MongoDB Document concepts in , The concepts of database and index are the same Mysql Agreement .
| Mysql | Mongodb |
|---|---|
| database | database |
| table | collection |
| row | document |
| index | index |
2. MongoDB Advantages and disadvantages of
First quote the first sentence of the official document :
Welcome to the MongoDB 4.2 Manual! MongoDB is a document database designed for ease of development and scaling
Translated into Chinese is :
Welcome to use MongoDB 4.2 manual !MongoDB It's a document database , Designed to facilitate development and expansion .
therefore MongoDB What we want to provide at the beginning of the design is a platform that can simplify the development 、 Support extended database , At the same time, it has high performance 、 High availability features .
① Simplify the development : The data is similar to JSON The key value of the file stores the formal document , This design pattern has fewer constraints on data , At the same time, documents correspond to native data types in many programming languages , Very easy to develop .
② Scalable : Traditional vertical expansion is limited to the performance of a single server . and MongoDB Sharding mode supports horizontal expansion , Expand the database capacity by increasing the number of servers .
③ High performance : WiredTiger Under the storage engine , Writing data to memory is complete , The operation of persisting to the hard disk is completed asynchronously in the background . At the same time, the replica set is read-write separated , Multi write in sharding mode can improve throughput to a greater extent .
④ High availability : Replica set mode synchronizes data on one or more replica servers , And support automatic failover , At the same time, it provides redundant backup of data , Improved data availability , Ensure the security of data .
although MongoDB apparent advantages , stay 4.2 Version also introduces distributed transactions , However, applications with strong requirements for transactional performance are still not recommended MongDB, In addition, connecting different types of data on multiple dimensions is what relational databases are good at , It is also not recommended to use MongoDB.
Two 、MongoDB Characteristics of
1. Nested document model
MongoDB Documents ( For the sake of understanding Mongo A document in can be thought of as Mysql A piece of data ) A similar Json Key value pair format to store data , stay Mongo called Bson. And MongoDB The document can embed the document structure into fields or arrays in the document , As shown in the figure below .
The nested document model allows applications to store relevant pieces of information in the same database record . therefore , Applications can perform common operations with fewer queries and updates , Improved performance . And this non standardized data model combines all relevant data in one document , Instead of normalizing across multiple documents and collections , Contribute to atomic operation .
2. Model freedom
In a relational database , We must first declare a table structure , And in the MongoDB By default, a set is not required ( It can be understood as approximately equal to Mysql In the table ) Documents in have the same fields , And the same field can have different data types in different documents . As shown below, the first data is the name 、 Age 、 Gender , The second data is gender 、 Age 、 height .
> db.test.insert({
"name":"xiaoming","age":"18","sex":" male "});
WriteResult({
"nInserted" : 1 })
>
> db.test.insert({
"name":"xiaohong","age":"16","height":"165"});
WriteResult({
"nInserted" : 1 })
>
> db.test.find()
{
"_id" : ObjectId("62b49cda779f3b59142bb909"), "name" : "xiaoming", "age" : "18", "sex" : " male " }
{
"_id" : ObjectId("62b49d25779f3b59142bb90a"), "name" : "xiaohong", "age" : "16", "height" : "165" }
>
3.2 Version start MongoDB The specified validation rule is introduced , That is, when inserting or updating, the data is verified according to the verification rules formulated by the user . stay 3.6 Version introduced Json Validation rules for patterns .
3. reliability
MongoDB Support replica set mode , Provide real-time data backup and automatic failover .
The smallest replica set cluster needs to be deployed in 3 Servers , They are the main nodes (Primary)、 From the node (Secondary) And arbitration nodes (Arbiter). The master node will synchronize the data to the slave node in real time to realize data backup , If the master node is abnormal, the slave node will be upgraded to the master node , Automatic failover .
4. Extensibility
When considering increasing the system load , Vertical expansion or horizontal expansion is usually considered . Vertical expansion means that a single server is added CPU、 Memory 、 Storage and other resources , This expansion method seriously challenges the hardware limitations of a single server , And the expansion cost is high . Horizontal expansion is to increase the system capacity by increasing the number of servers , Not limited by single server hardware , Multiple servers work together , But it is more complicated than vertical expansion .
MongoDB The sharding mode of is a method of distributing data among multiple machines . Sharding mode can be used to support very large data sets and high-throughput operations . The components of the slice mode are shown in the following figure .
5. Support distributed transactions
For cases that require atomic operations on multiple documents ,MongoDB stay 4.0 The version began to support multiple document transactions in replica set mode ,4.2 The version starts to support transactions of partitioned clusters , Implemented distributed transactions , thus MongoDB It can also completely replace the use of relational databases . Use distributed transactions , Can span multiple operations 、 aggregate 、 database 、 Documents and sharding use transactions .
6. File store
BSON Limit the maximum storage capacity of a document 16MB data , If our file is smaller than 16MB, Files can be converted into binary data and stored in collections in the form of documents . meanwhile MongoDB Also available for storing and retrieving more than 16 MB File specification for , namely GridFS.
GridFS Split the file into blocks and save to multiple documents , This method makes it unnecessary to load the whole file into memory when we want to read part of the file information , It may be more efficient than the system level file system when facing large files .GridFS Not only can it be used to store more than 16 MB The file of , Any file can also be stored , but MongoDB It is recommended that if all the files we want to store are smaller than 16MB Limit time , Priority should be given to storing each file in a single document rather than GridFS.
Reference resources
《MongoDB Core principles and practices 》 Guo Yuanwei Writing
Mongodb Official documents :https://www.mongodb.com/docs/v4.2/
边栏推荐
- Teach you how to implement a deep learning framework
- C语言课设物业费管理系统(大作业)
- Flink practice -- multi stream merge
- SystemVerilog learning-08-random constraints and thread control
- High order binary balanced tree
- 三分钟带你快速了解网站开发的整个流程
- Forkjoin and stream flow test
- 68 cesium code datasource loading czml
- Make: g++: command not found
- 【ManageEngine】终端管理系统,助力华盛证券数字化转型
猜你喜欢

Distributed lock implementation

B-树系列
![[enterprise data security] upgrade backup strategy to ensure enterprise data security](/img/59/e44c6533aa546e8854ef434aa64113.png)
[enterprise data security] upgrade backup strategy to ensure enterprise data security

B-tree series

高阶-二叉平衡树

蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是

ForkJoin和Stream流测试
![[file system] how to run squashfs on UBI](/img/d7/a4769420c510c47f3c2a615b514a8e.png)
[file system] how to run squashfs on UBI

Redis安装到Windows系统上的详细步骤

FPGA - 7 Series FPGA internal structure clocking-01-clock Architecture Overview
随机推荐
Although pycharm is marked with red in the run-time search path, it does not affect the execution of the program
JDBC database operation
XAF Bo of dev XPO comparison
What are the functions of LAN monitoring software
ArcServer密码重置(账号不可以重置)
网络爬虫
Application of IT service management (ITSM) in Higher Education
Understanding of C manualresetevent class
Kubedm builds kubenetes cluster (Personal Learning version)
JMM详解
【ManageEngine卓豪】用统一终端管理助“欧力士集团”数字化转型
SystemVerilog learning-09-interprocess synchronization, communication and virtual methods
Flink practice -- multi stream merge
数据库产生死锁了请问一下有没有解决办法
Solve the problem of garbled files uploaded by Kirin v10
Self confidence is indispensable for technology
局域网监控软件有哪些功能
How does the port scanning tool help enterprises?
kubeadm搭建kubenetes 集群(个人学习版)
[file system] how to run squashfs on UBI