Skip to content

Commit 03315c7

Browse files
committed
Use MongoReplicaSetClient only if replicaSet option is enabled
1 parent 5fa8a63 commit 03315c7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

django_mongodb_engine/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.core.exceptions import ImproperlyConfigured
99
from django.db.backends.signals import connection_created
1010
from django.db.utils import DatabaseError
11+
from pymongo import ReadPreference
1112

1213
from pymongo.collection import Collection
1314
from pymongo.mongo_client import MongoClient
@@ -230,13 +231,16 @@ def pop(name, default=None):
230231
options[key.lower()] = options.pop(key)
231232

232233
read_preference = options.get('read_preference')
234+
replicaset = options.get('replicaset')
235+
233236
if not read_preference:
234237
read_preference = options.get('slave_okay', options.get('slaveok'))
235238
if read_preference:
239+
options['read_preference'] = ReadPreference.SECONDARY
236240
warnings.warn("slave_okay has been deprecated. "
237241
"Please use read_preference instead.")
238242

239-
if read_preference:
243+
if replicaset:
240244
connection = MongoReplicaSetClient
241245
else:
242246
connection = MongoClient

0 commit comments

Comments
 (0)