File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -1444,8 +1444,16 @@ def _cursor_args(self):
14441444 def _cursor (self ):
14451445 if self ._cursor_obj is None :
14461446
1447- self ._cursor_obj = self ._collection .find (self ._query ,
1448- ** self ._cursor_args )
1447+ # In PyMongo 3+, we define the read preference on a collection
1448+ # level, not a cursor level. Thus, we need to get a cloned
1449+ # collection object using `with_options` first.
1450+ if IS_PYMONGO_3 and self ._read_preference is not None :
1451+ self ._cursor_obj = self ._collection \
1452+ .with_options (read_preference = self ._read_preference )\
1453+ .find (self ._query , ** self ._cursor_args )
1454+ else :
1455+ self ._cursor_obj = self ._collection .find (self ._query ,
1456+ ** self ._cursor_args )
14491457 # Apply where clauses to cursor
14501458 if self ._where_clause :
14511459 where_clause = self ._sub_js_fields (self ._where_clause )
You can’t perform that action at this time.
0 commit comments