fix: Enable reading from secondaries in the MongoDB driver.
This patch changes the MongoDB driver so that it will use MongoReplicaSetClient instead of MongoClient when a replicaSet is specified in the connection URI. Testing revealed that this is necessary for readPreference to be respected. Change-Id: I3c1a2a166c5dd2c857cd52a2d1766437a9e4a940
This commit is contained in:
@@ -44,7 +44,11 @@ class Driver(storage.DriverBase):
|
||||
mongodb's database.
|
||||
"""
|
||||
if not self._database:
|
||||
conn = pymongo.MongoClient(cfg.uri)
|
||||
if cfg.uri and 'replicaSet' in cfg.uri:
|
||||
conn = pymongo.MongoReplicaSetClient(cfg.uri)
|
||||
else:
|
||||
conn = pymongo.MongoClient(cfg.uri)
|
||||
|
||||
self._database = conn[cfg.database]
|
||||
|
||||
return self._database
|
||||
|
||||
Reference in New Issue
Block a user