@@ -299,11 +299,15 @@ 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 )
302304
303305 if  use_cmd :
304306 ns  =  _UJOIN  %  (self .db , "$cmd" )
305307 spec  =  self .as_command (sock_info )[0 ]
306308 ntoreturn  =  - 1  # All DB commands return 1 document 
309+  return  query (flags , ns , self .ntoskip , ntoreturn ,
310+  spec , None , self .codec_options )
307311 else :
308312 # OP_QUERY treats ntoreturn of -1 and 1 the same, return 
309313 # 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):
314318 ntoreturn  =  min (self .limit , ntoreturn )
315319 else :
316320 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 )
324323
325324
326325class  _GetMore (object ):
0 commit comments