Skip to content

Commit cd37dfe

Browse files
committed
Use MongoClient or MongoReplicaSet client instead of Connection
1 parent cb2ff80 commit cd37dfe

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

django_mongodb_engine/base.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
import datetime
33
import decimal
44
import sys
5+
import warnings
56

67
from django.conf import settings
78
from django.core.exceptions import ImproperlyConfigured
89
from django.db.backends.signals import connection_created
910
from django.db.utils import DatabaseError
1011

1112
from pymongo.collection import Collection
12-
from pymongo.connection import Connection
13+
from pymongo.mongo_client import MongoClient
14+
from pymongo.mongo_replica_set_client import MongoReplicaSetClient
1315

1416
# handle pymongo backward compatibility
1517
try:
@@ -226,7 +228,19 @@ def pop(name, default=None):
226228
for key in options.iterkeys():
227229
options[key.lower()] = options.pop(key)
228230

229-
try:
231+
read_preference = options.get('read_preference')
232+
if not read_preference:
233+
read_preference = options.get('slave_okay', options.get('slaveok'))
234+
if read_preference:
235+
warnings.warn("slave_okay has been deprecated. "
236+
"Please use read_preference instead.")
237+
238+
if read_preference:
239+
Connection = MongoReplicaSetClient
240+
else:
241+
Connection = MongoClient
242+
243+
try:
230244
self.connection = Connection(host=host, port=port, **options)
231245
self.database = self.connection[db_name]
232246
except TypeError:

0 commit comments

Comments
 (0)