Open linearb opened 8 years ago
Are there any updates regarding this request ? It would be really useful if this was supported, without this feature using replicaSet is pointless since all connections are always directed to the primary.
If someone would like to get their hands dirty and contribute a PR, we'd be happy to review. :)
txmongo should, like pymongo, fully support read preferences, to permit, for example, failover to primary, or nearest. Behavior, should be like pymongo 3.2.2 as described here: https://api.mongodb.org/python/current/api/pymongo/read_preferences.html#module-pymongo.read_preferences.
PRIMARY: Read from the primary. This is the default read preference, and provides the strongest consistency. If no primary is available, raise AutoReconnect. PRIMARY_PREFERRED: Read from the primary if available, otherwise read from a secondary. SECONDARY: Read from a secondary. If no matching secondary is available, raise AutoReconnect. SECONDARY_PREFERRED: Read from a secondary if available, otherwise from the primary. NEAREST: Read from any available member.
(Note an edge case that should be handled correctly: pymongo, when connected to a mongod that happens to be a member of a replica set, using SECONDARY and the replicaSet option unset, does not failover to other replicaset members. But the current txmongo code seems to append the members of the set to __allnodes whether or not replicaSet is set. )