File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 2
2
import datetime
3
3
import decimal
4
4
import sys
5
+ import warnings
5
6
6
7
from django .conf import settings
7
8
from django .core .exceptions import ImproperlyConfigured
8
9
from django .db .backends .signals import connection_created
9
10
from django .db .utils import DatabaseError
10
11
11
12
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
13
15
14
16
# handle pymongo backward compatibility
15
17
try :
@@ -226,7 +228,19 @@ def pop(name, default=None):
226
228
for key in options .iterkeys ():
227
229
options [key .lower ()] = options .pop (key )
228
230
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 :
230
244
self .connection = Connection (host = host , port = port , ** options )
231
245
self .database = self .connection [db_name ]
232
246
except TypeError :
You can’t perform that action at this time.
0 commit comments