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