skip to main content
Connection Property Descriptions : ReadPreference
  

Try DataDirect Drivers Now

ReadPreference

Purpose

Specifies a preference for the type of member (server node) of a replica set to which the driver attempts to connect. Connections to the primary member (read-write server nodes) return the most recent version of the data when executing Select queries, but increase the workload of the primary member and may negatively affect performance. To reduce the demand on the primary member, secondary members (read-only server nodes) can be used at the expense of reading stale data.

Valid Values

none | primary | primaryPreferred | secondary | secondaryPreferred

Behavior

If set to none, the driver attempts to connect to only the member authorized by the application.
If set to primary, the driver attempts to connect to only the primary member of a replica set. If the primary member is unavailable, the connection fails.
If set to primaryPreferred, the driver attempts to connect to the primary member first; but if it is unavailable, the driver attempts to connect to secondary members.
If set to secondary, the driver attempts to connect to only secondary members of a replica set. If the secondary members of the replica set are unavailable, the connection fails.
If set to secondaryPreferred, the driver attempts to connect to secondary members first; but if they are unavailable, the driver attempts to connect to the primary member.

Notes

*When connected to secondary members (read-only) of a replica set, the driver will return an error when attempting to execute write operations. To enable write operations, disconnect from the secondary member and establish a new connection to a primary (read-write) member. You should verify that the ReadPreference property is configured to tolerate a connection to a primary member before attempting to establish the new connection.
*If the ReadPreference property is configured to connect to a secondary member, the replica set that the driver is connecting to must contain a secondary member. If no secondary member exists, the driver will return an error.

Default

primary

See also

*Using Connection Properties
*Performance Considerations