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