Beispiel #1
0
    def remove(self, spec_or_id={}, safe=True, callback=None):
        """remove a document

        :Parameters:
        - `spec_or_id`: a query or a document id
        - `safe` (optional): safe insert operation
        - `callback` : method which will be called when save is finished
        """
        if not isinstance(spec_or_id, dict):
            spec_or_id = {"_id": spec_or_id}

        assert isinstance(spec_or_id, dict)

        message_delete = message.delete(self._collection_name, spec_or_id,
                                        safe, {})

        log.debug("mongo: db.{0}.remove({1})".format(self._collection_name,
                                                     spec_or_id))
        node = yield gen.Task(self._database.get_node, ReadPreference.PRIMARY)
        connection = yield gen.Task(node.connection)

        response, error = yield gen.Task(connection.send_message,
                                         message_delete, safe)

        if callback:
            callback((response, error))
Beispiel #2
0
    def remove(self, spec_or_id={}, safe=True, callback=None):
        """remove a document

        :Parameters:
        - `spec_or_id`: a query or a document id
        - `safe` (optional): safe insert operation
        - `callback` : method which will be called when save is finished
        """
        if not isinstance(spec_or_id, dict):
            spec_or_id = {"_id": spec_or_id}

        assert isinstance(spec_or_id, dict)

        message_delete = message.delete(self._collection_name, spec_or_id,
            safe, {})

        log.debug("mongo: db.{0}.remove({1})".format(self._collection_name, spec_or_id))
        node = yield gen.Task(self._database.get_node, ReadPreference.PRIMARY)
        connection = yield gen.Task(node.connection)

        response, error = yield gen.Task(connection.send_message,
            message_delete, safe)

        if callback:
            callback((response, error))
Beispiel #3
0
    def truncate(self, callback=None):
        collection_name = Database().get_collection_name(self.collection.__collection__)
        message_delete = message.delete(collection_name, {}, True, {})

        yield gen.Task(Database().send_message, message_delete)

        if callback:
            callback()
Beispiel #4
0
    def truncate(self, callback=None):
        collection_name = Database().get_collection_name(
            self.collection.__collection__)
        message_delete = message.delete(collection_name, {}, True, {})

        yield gen.Task(Database().send_message, message_delete)

        if callback:
            callback()
Beispiel #5
0
    def tearDown(self):
        super(CursorTestCase, self).tearDown()

        # delete all documents
        message_delete = message.delete('mongotor_test.cursor_test',
            {}, True, {})
        Database().send_message(message_delete, callback=self.stop)
        self.wait()

        Database.disconnect()
Beispiel #6
0
    def tearDown(self):
        super(CursorTestCase, self).tearDown()

        # delete all documents
        message_delete = message.delete('mongotor_test.cursor_test', {}, True,
                                        {})
        Database().send_message(message_delete, callback=self.stop)
        self.wait()

        Database.disconnect()
Beispiel #7
0
    def tearDown(self):
        super(CursorTestCase, self).tearDown()

        # delete all documents
        message_delete = message.delete('mongotor_test.cursor_test',
            {}, True, {})

        node = Database().get_node(ReadPreference.PRIMARY)
        node.connection(self.stop)
        connection = self.wait()

        connection.send_message(message_delete, with_last_error=True, callback=self.stop)
        self.wait()

        Database.disconnect()
Beispiel #8
0
    def tearDown(self):
        super(CursorTestCase, self).tearDown()

        # delete all documents
        message_delete = message.delete('mongotor_test.cursor_test', {}, True,
                                        {})

        Database().get_node(ReadPreference.PRIMARY, callback=self.stop)
        node = self.wait()
        node.connection(self.stop)
        connection = self.wait()

        connection.send_message(message_delete,
                                with_last_error=True,
                                callback=self.stop)
        self.wait()

        Database.disconnect()
Beispiel #9
0
    def remove(self, spec_or_id={}, safe=True, callback=None):
        """remove a document

        :Parameters:
        - `spec_or_id`: a query or a document id
        - `safe` (optional): safe insert operation
        - `callback` : method which will be called when save is finished
        """
        if not isinstance(spec_or_id, dict):
            spec_or_id = {"_id": spec_or_id}

        assert isinstance(spec_or_id, dict)

        msg = message.delete(self._collection_name, spec_or_id,
                             safe, {})
        log.debug("mongo: db.{0}.remove({1})".format(self._collection_name, spec_or_id))
        node = self._database.get_node(ReadPreference.PRIMARY)
        node.connection(lambda conn: conn.send_message(msg, safe, False, callback))
Beispiel #10
0
    def remove(self, safe=True, callback=None):
        """Remove a document

        :Parameters:
        - `safe` (optional): safe remove operation
        - `callback` : method which will be called when remove is finished
        """
        pre_remove.send(instance=self)

        database = Database()
        collection_name = database.get_collection_name(self.__collection__)

        message_delete = message.delete(collection_name, {'_id': self._id},
            safe, {})

        response, error = yield gen.Task(database.send_message, message_delete)

        post_remove.send(instance=self)

        if callback:
            callback((response, error))
Beispiel #11
0
    def remove(self, spec_or_id={}, safe=True, callback=None):
        """remove a document

        :Parameters:
        - `spec_or_id`: a query or a document id
        - `safe` (optional): safe insert operation
        - `callback` : method which will be called when save is finished
        """
        if not isinstance(spec_or_id, dict):
            spec_or_id = {"_id": spec_or_id}

        assert isinstance(spec_or_id, dict)

        message_delete = message.delete(self._collection_name, spec_or_id,
            safe, {})

        response, error = yield gen.Task(self._database.send_message,
            message_delete, read_preference=ReadPreference.PRIMARY)

        if callback:
            callback((response, error))