'Perform an atomic update on the fields matched by the query.
:param upsert: insert if document doesn\'t exist (default ``False``)
:param multi: Update multiple documents.
:param write_concern: Extra keyword arguments are passed down which
will be used as options for the resultant
``getLastError`` command.  For example,
``save(..., write_concern={w: 2, fsync: True}, ...)`` will
wait until at least two servers have recorded the write and
will force an fsync on the primary server.
:param full_result: Return the full result rather than just the number
updated.
:param update: Django-style update keyword arguments
.. versionadded:: 0.2'

def update(self, upsert=False, multi=True, write_concern=None, full_result=False, **update):

    if ((not update) and (not upsert)):
        raise OperationError('No    update    parameters,    would    remove    data')
    if (write_concern is None):
        write_concern = {}
    queryset = self.clone()
    query = queryset._query
    update = transform.update(queryset._document, **update)
    if (upsert and ('_cls' in query)):
        if ('$set' in update):
            update['$set']['_cls'] = queryset._document._class_name
        else:
            update['$set'] = {'_cls': queryset._document._class_name}
    try:
        result = queryset._collection.update(query, update, multi=multi, upsert=upsert, **write_concern)
        if full_result:
            return result
        elif result:
            return result['n']
    except pymongo.errors.DuplicateKeyError as err:
        raise NotUniqueError((u'Update    failed    (%s)' % six.text_type(err)))
    except pymongo.errors.OperationFailure as err:
        if (six.text_type(err) == u'multi    not    coded    yet'):
            message = u'update()    method    requires    MongoDB    1.1.3+'
            raise OperationError(message)
        raise OperationError((u'Update    failed    (%s)' % six.text_type(err)))
