@@ -299,15 +299,11 @@ def get_message(self, set_slave_ok, sock_info, use_cmd=False):
299299
300300 ns = _UJOIN % (self .db , self .coll )
301301 spec = self .spec
302- if sock_info .is_mongos :
303- spec = _maybe_add_read_preference (spec , self .read_preference )
304302
305303 if use_cmd :
306304 ns = _UJOIN % (self .db , "$cmd" )
307305 spec = self .as_command (sock_info )[0 ]
308306 ntoreturn = - 1 # All DB commands return 1 document
309- return query (flags , ns , self .ntoskip , ntoreturn ,
310- spec , None , self .codec_options )
311307 else :
312308 # OP_QUERY treats ntoreturn of -1 and 1 the same, return
313309 # 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):
318314 ntoreturn = min (self .limit , ntoreturn )
319315 else :
320316 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 )
323324
324325
325326class _GetMore (object ):
0 commit comments