Example #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))
Example #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))
Example #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()
Example #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()
Example #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()
Example #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()
Example #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()
Example #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()
Example #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))
Example #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))
Example #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))