def find(self, callback=None): message_query = message.query(self._query_options(), self._collection_name, self._skip, self._limit, self._query_spec(), self._fields) if self._connection: response, error = yield gen.Task(self._connection.send_message, message_query) else: response, error = yield gen.Task(self._database.send_message, message_query, read_preference=self._read_preference) # close cursor if response and response.get('cursor_id'): cursor_id = response['cursor_id'] if self._connection: self._connection.send_message(message.kill_cursors([cursor_id]), callback=None) else: self._database.send_message(message.kill_cursors([cursor_id]), callback=None) if error: callback((None, error)) else: if self._limit == -1 and len(response['data']) == 1: callback((response['data'][0], None)) else: callback((response['data'], None))
def find(self, skip=0, limit=0, sort=None, callback=None): self._ordering = sort message_query = message.query(self._query_options(), self._collection_name, skip, limit, self._query_spec(), self._fields) response, error = yield gen.Task(Database().send_message, message_query) # close cursor if response and response.get('cursor_id'): cursor_id = response['cursor_id'] Database().send_message(message.kill_cursors([cursor_id]), callback=None) if error: callback((None, error)) else: if limit == -1 and len(response['data']) == 1: callback((response['data'][0], None)) else: callback((response['data'], None))
def find(self, callback=None): message_query = message.query(self._query_options(), self._collection_name, self._skip, self._limit, self._query_spec(), self._fields) if not self._connection: node = yield gen.Task(self._database.get_node, self._read_preference) connection = yield gen.Task(node.connection) else: connection = self._connection response, _ = yield gen.Task(connection.send_message_with_response, message_query) response = helpers._unpack_response(response) # close cursor if response and response.get('cursor_id'): cursor_id = response['cursor_id'] connection.send_message(message.kill_cursors([cursor_id]), callback=None) if self._limit == -1 and len(response['data']) == 1: callback((response['data'][0], None)) else: callback((response['data'], None))
def find(self, callback=None): message_query = message.query(self._query_options(), self._collection_name, self._skip, self._limit, self._query_spec(), self._fields) if not self._connection: node = self._database.get_node(self._read_preference) connection = yield gen.Task(node.connection) else: connection = self._connection response, _ = yield gen.Task(connection.send_message_with_response, message_query) response = helpers._unpack_response(response) # close cursor if response and response.get('cursor_id'): cursor_id = response['cursor_id'] connection.send_message(message.kill_cursors([cursor_id]), callback=None) if self._limit == -1 and len(response['data']) == 1: callback((response['data'][0], None)) else: callback((response['data'], None))