'Get a query message, possibly setting the slaveOk bit.'

def get_message(self, set_slave_ok, is_mongos, use_cmd=False):

    if set_slave_ok:
        flags = (self.flags | 4)
    else:
        flags = self.flags
    ns = (_UJOIN % (self.db, self.coll))
    spec = self.spec
    if use_cmd:
        ns = (_UJOIN % (self.db, '$cmd'))
        spec = self.as_command()[0]
        ntoreturn = (-1)
    else:
        ntoreturn = (((self.batch_size == 1) and 2) or self.batch_size)
        if self.limit:
            if ntoreturn:
                ntoreturn = min(self.limit, ntoreturn)
            else:
                ntoreturn = self.limit
    if is_mongos:
        spec = _maybe_add_read_preference(spec, self.read_preference)
    return query(flags, ns, self.ntoskip, ntoreturn, spec, self.fields, self.codec_options)
