C # connect MongoDB replica set read-write detached string configuration

Source: Internet
Author: User

One, replica set configuration

Set up, 1 main instances, 1 units from the instance, 1 arbitration instances. MongoDB recommends an odd number of machines in a replica set

Second, C # connection string

1. Read

Mongodb://secondary.com/?slaveok=true

2. Write

Mongodb://primary.com

Third, experience

1. Using a 1.7 C # driver, do not support configuring/?readpreference=secondary or/?readpreference=secondarypreferred directly in the connection string

2.readPreference parameters

Primary: The default parameter, only read from the primary node;
Primarypreferred: Most of the data is read from the primary node, and the data is read from the secondary node only when the primary node is unavailable.
Secondary: Only read from the secondary node, the problem is that the data of the secondary node is "old" than the primary node data.
Secondarypreferred: read from the secondary node, and read data from the master node when the secondary node is unavailable;
Nearest: Read data from the node with the lowest network latency, whether it is the primary node or the secondary node

Iv. Learning Materials

Reference Link: https://docs.mongodb.org/manual/core/read-preference/

C # connect MongoDB replica set read-write detached string configuration

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: info-contact@alibabacloud.com 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.