Mongodb-replica Set Read and Write

Source: Internet
Author: User

Regardless of whether MongoDB exists as a single node or as a replica set, it is transparent to the application. By default, MongoDB read requests are performed on the primary node and remain consistent with the last write operation. The user can configure the replication set read option for each connection to send its read request to the slave node. This situation is generally related to the eventual consistency of the data, although the data set from the node will eventually be consistent with the master node, but the read operations from the node do not guarantee strict data consistency. To ensure data consistency from the read operation of the node, the client can be configured to ensure that the write operation is applied to all nodes of the replication set for success.

Write Concern for Replica set Verify Write Operations to Replica set

Replica set under the default secure write level, only confirm that the data is written to the master node. However, we can modify the secure write level to ensure that the write operation completes the write operation at the specified number of nodes in the replication set.

We can bypass the default security write level by specifying a secure write level for each write operation. Setting a time-out limit at the secure write level avoids blocking when the replica set node does not reach the target.

Modify Default Write Concern

We can set the default security level for replication sets by modifying the getlasterrordefaults in the replica set configuration. The following configuration command effect is: The write operation is completed only after the majority of the nodes in the replication set respond.

Custom Write Concerns

You can label a member of a replication set and then set the security level based on the label.

Read Preference

The copy set read option determines how the read operation is routed in the replication set.

Use Cases indications counter-indications read Preference Modes Tag sets read Preference Processes

Mongodb-replica Set Read and Write

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.