@@ -299,11 +299,15 @@ def get_message(self, set_slave_ok, sock_info, use_cmd=False):
299
299
300
300
ns = _UJOIN % (self .db , self .coll )
301
301
spec = self .spec
302
+ if sock_info .is_mongos :
303
+ spec = _maybe_add_read_preference (spec , self .read_preference )
302
304
303
305
if use_cmd :
304
306
ns = _UJOIN % (self .db , "$cmd" )
305
307
spec = self .as_command (sock_info )[0 ]
306
308
ntoreturn = - 1 # All DB commands return 1 document
309
+ return query (flags , ns , self .ntoskip , ntoreturn ,
310
+ spec , None , self .codec_options )
307
311
else :
308
312
# OP_QUERY treats ntoreturn of -1 and 1 the same, return
309
313
# one document and close the cursor. We have to use 2 for
@@ -314,13 +318,8 @@ def get_message(self, set_slave_ok, sock_info, use_cmd=False):
314
318
ntoreturn = min (self .limit , ntoreturn )
315
319
else :
316
320
ntoreturn = self .limit
317
-
318
- if sock_info .is_mongos :
319
- spec = _maybe_add_read_preference (spec ,
320
- self .read_preference )
321
-
322
- return query (flags , ns , self .ntoskip , ntoreturn ,
323
- spec , self .fields , self .codec_options )
321
+ return query (flags , ns , self .ntoskip , ntoreturn ,
322
+ spec , self .fields , self .codec_options )
324
323
325
324
326
325
class _GetMore (object ):
0 commit comments