Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[MongoDB] ReadPreference reading preference

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The setting of ReadPreference is only involved in the replica set Replica Set. By default, both reads and writes are executed by the Primary node. But in the case of fewer writes and more reads, we want to separate read and write to share the pressure, so we want to use the Secondary node for reading. Primary only takes the responsibility of writing (in fact, writes can only be distributed to the Primary node and cannot be modified).

MongoDB has five ReadPreference modes:

Primary

Master node, default mode, read operation is only on the primary node, if the primary node is not available, an error is reported or an exception is thrown.

PrimaryPreferred

The preferred master node, in most cases, the read operation is on the master node, and if the master node is not available, such as failover, the read operation is on the slave node.

Secondary

Slave node, read operation is only on slave node, if slave node is not available, an error is reported or an exception is thrown.

SecondaryPreferred

The slave node is preferred, in most cases, the read operation is on the slave node, and in special cases (such as single master node architecture), the read operation is on the master node.

Nearest

The nearest node, the read operation in the nearest member, may be the master node or the slave node.

Settings in Spring ReadPreference:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report