Skip to Content
MongoDB权威指南(第3版)
book

MongoDB权威指南(第3版)

by Shannon Bradshaw, Eoin Brazil, Kristina Chodorow
November 2021
Intermediate to advanced
410 pages
12h 1m
Chinese
Posts & Telecom Press
Content preview from MongoDB权威指南(第3版)
184
9
要理解如何实现这些不同级别的一致性,就必须了解
MongoDB
的内部机制。服务器端为
各个数据库连接维护了一个请求队列。客户端每次发来的新请求都会被添加到队列的末
尾。连接中的任何后续请求都将依次得到处理。因此,单个连接具有一致的数据库视图,
并且始终可以读取到自己的写操作。
注意,每个列队只对应一个连接:如果打开两个
shell
,连接到相同的数据库
,则会有两个
不同的连接。如果在一个
shell
中执行插入操作
,那么另一个
shell
中的后续查询可能不会
返回插入的文档。然而,在同一个
shell
中,
如果在插入一个文档之后查询,则一定能够查
询到刚插入的文档。想手动重现这种问题可能很困难,但是在繁忙的服务器上,很可能会
出现交错的插入和查询操作。当开发人员使用一个线程插入数据,然后在另一个线程中检
查数据是否成功插入时经常会遇到这种情况。片刻之后,数据看起来好像没有插入成功,
然后又突然出现了。
在使用
Ruby
Python
Java
驱动程序时尤其需要注意这个问题
,因为这
3
种语言的驱动
程序都使用了连接池。为了提高效率,这些驱动程序会建立多个与服务器端的连接(也就
是一个
连接池
),并在它们之间分发请求。不过,它们都拥有各自的机制来保证由单个连
接处理一系列相关的请求。
MongoDB
动程序连接监控和连接池规范中有关于各种语言
连接池的详细文档。
当向副本集的从节点(参见第
12
章)发送读请求时
,这将成为一个更大的问题。从节点
数据可能落后于主节点,导致读取到的数据是几秒、几分钟甚至几小时之前的。有几种方 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Spark快速大数据分析(第2版)

Spark快速大数据分析(第2版)

Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9787115576538