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:
kgriffs
2013-04-09 19:30:29 -04:00
parent b94f4e6fe7
commit 84146af623

View File

@@ -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