Read Concern读取关注
Default Read Concern默认读取关注
The default read concern is as follows:默认的读取关注如下:
| |
|
Specify Read Concern: MongoDB Drivers指定读取关注:MongoDB驱动程序
Operations outside Transactions事务之外的操作
The following information applies to operations that are run outside transactions. For read concern information related to operations that are run inside transactions, click the 以下信息适用于在事务外部运行的操作。有关在事务中运行的操作的读取关注信息,请单击“事务中的操作”选项卡。Operations in Transactions tab.
Using the MongoDB drivers, you can override the default read concern and set read concern for operations at the following levels:使用MongoDB驱动程序,您可以覆盖默认的读取关注,并在以下级别为操作设置读取关注:
| |
| |
|
Operations in Transactions事务中的操作
The following information applies to operations that are run inside transactions. For read concern information related to operations that are run outside transactions, click the 以下信息适用于在事务内部运行的操作。有关在事务外部运行的操作的读取关注信息,请单击“事务外部的操作”选项卡。Operations outside Transactions tab.
Using the MongoDB drivers,you can override the default read concern and set read concern for transactions at the following levels:使用MongoDB驱动程序,您可以覆盖默认的读取关注,并在以下级别为事务设置读取关注:
| |
| |
|
Additional Information附加信息
For more information on the available read concerns, see Read Concern.有关可用读取关注的更多信息,请参阅读取关注。
Write Concern写入关注
Default Write Concern默认写入关注
The implicit default write concern is 隐含的默认写入关注是w: majority. w: majority。w: majority ensures write durability by requiring replica sets to wait for on-disk journaling by default, controlled by 默认情况下,通过要求副本集等待磁盘上的日志记录来确保写入持久性,该日志记录由writeConcernMajorityJournalDefault. writeConcernMajorityJournalDefault控制。However, there is an edge case for replica set deployments containing arbiters:但是,包含仲裁器的副本集部署存在一个边缘情况:
The voting majority of a replica set is 1 plus half the number of voting members, rounded down. If the number of data-bearing voting members is not greater than the voting majority, the default write concern is复制品集的投票多数为1加上投票成员人数的一半,四舍五入。如果携带数据的投票成员数量不大于投票多数,则默认写入关注为{ w: 1 }.{w:1}。In all other scenarios, the default write concern is在所有其他情况下,默认的写入关注是{ w: "majority" }.{ w: "majority" }。
Specifically, MongoDB uses the following formula to determine the default write concern:具体来说,MongoDB使用以下公式来确定默认的写入关注:
if [ (#arbiters > 0) AND (#non-arbiters <= majority(#voting-nodes)) ]
defaultWriteConcern = { w: 1 }
else
defaultWriteConcern = { w: "majority" }
For example, consider the following deployments and their respective default write concerns:例如,考虑以下部署及其各自的默认写入关注:
| 2 | 1 | 3 | 2 | { w: 1 } |
| 4 | 1 | 5 | 3 | { w: "majority" } |
In the first example:在第一个例子中:There are 2 non-arbiters and 1 arbiter for a total of 3 voting nodes.共有3个投票节点,有2个非仲裁器和1个仲裁器。The majority of voting nodes (1 plus half of 3, rounded down) is 2.大多数投票节点(1加上3的一半,四舍五入)为2。The number of non-arbiters (2) is equal to the majority of voting nodes (2), resulting in an implicit write concern of非仲裁者(2)的数量等于大多数投票节点(2),导致隐式写入关注{ w: 1 }.{w:1}。
In the second example:在第二个例子中:There are 4 non-arbiters and 1 arbiter for a total of 5 voting nodes.共有5个投票节点,有4个非仲裁者和1个仲裁者。The majority of voting nodes (1 plus half of 5, rounded down) is 3.大多数投票节点(1加上5的一半,四舍五入)为3。The number of non-arbiters (4) is greater than the majority of voting nodes (3), resulting in an implicit write concern of非仲裁者的数量(4)大于大多数投票节点的数量(3),导致隐含的写入关注{ w: "majority" }.{ w: "majority" }。
Specify Write Concern: MongoDB Drivers指定写入关注:MongoDB驱动程序
Operations outside Transactions事务之外的操作
The following information applies to operations that are run outside transactions. 以下信息适用于在事务外部运行的操作。For read concern information related to operations that are run inside transactions, click the 有关在事务中运行的操作的读取关注信息,请单击“事务中的操作”选项卡。Operations in Transactions tab.
Using the MongoDB drivers, you can override the default write concern and set write concern for operations at the following levels:使用MongoDB驱动程序,您可以覆盖默认写入关注,并在以下级别设置操作的写入关注:
| Client level | |
| |
| |
|
Operations in Transactions事务中的操作
The following information applies to operations that are run inside transactions. 以下信息适用于在事务内部运行的操作。For read concern information related to operations that are run outside transactions, click the 有关在事务外部运行的操作的读取关注信息,请单击“事务外部的操作”选项卡。Operations outside Transactions tab.
Using the MongoDB drivers, you can override the default write concern and set write concern for for transactions at the following levels:使用MongoDB驱动程序,您可以覆盖默认的写入关注,并在以下级别为事务设置写入关注:
| |
| Session level |
|
|
See Transactions and Write Concern for more information.有关更多信息,请参阅事务和写入关注。
Additional Information附加信息
For more information on the available write concerns, see Write Concern.有关可用写入关注的更多信息,请参阅写入关注。
Causal Consistency Guarantees因果一致性保证
With causally consistent client sessions, the client sessions only guarantee causal consistency if:对于因果一致的客户端会话,客户端会话仅在以下情况下保证因果一致性:
the associated read operations use相关的读取操作使用"majority"read concern, and"majority"读取关注,以及the associated write operations use相关的写入操作使用"majority"write concern."majority"写入关注。