当前位置:网站首页>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/
边栏推荐
- 【#Unity Shader#自定义材质面板_第二篇】
- 码力十足学量化|如何在财务报告寻找合适的财务公告
- 手把手教你实现一个深度学习框架...
- Recueillir des trésors dans le palais souterrain (recherche de mémoire profonde)
- Discrimination between left and right limits of derivatives and left and right derivatives
- lxml模块(数据提取)
- On siem
- Redis安装到Windows系统上的详细步骤
- 【网络安全工具】USB控制软件有什么用
- c# Xml帮助类
猜你喜欢

【自动化运维】自动化运维平台有什么用

连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?

Solve the problem of garbled files uploaded by Kirin v10

C语言课设销售管理系统设计(大作业)

ArcServer密码重置(账号不可以重置)
![阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]](/img/3c/7684b7c594f7871471f89007294703.png)
阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]

High order binary search tree

Movable mechanical wall clock

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

Understanding of C manualresetevent class
随机推荐
Servlet
JDBC database operation
Restframework-simplejwt rewrite authentication mechanism
ABP 学习解决方案中的项目以及依赖关系
C# ManualResetEvent 类的理解
JMM详解
[enterprise data security] upgrade backup strategy to ensure enterprise data security
Tidb database characteristics summary
SystemVerilog learning-10-validation quantification and coverage
【#Unity Shader#自定义材质面板_第二篇】
【LeetCode】Day91-存在重复元素
High order binary search tree
[summary of problem thinking] Why is the register reset performed in user mode?
sql中TCL语句(事务控制语句)
Uniapp tree level selector
Flink practice -- multi stream merge
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
数据库产生死锁了请问一下有没有解决办法
10 golang operator
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village