'Performs an update on the :class:`~mongoengine.Document`
A convenience wrapper to :meth:`~mongoengine.QuerySet.update`.
Raises :class:`OperationError` if called on an object that has not yet
been saved.'

def update(self, **kwargs):

    if (self.pk is None):
        if kwargs.get('upsert', False):
            query = self.to_mongo()
            if ('_cls' in query):
                del query['_cls']
            return self._qs.filter(**query).update_one(**kwargs)
        else:
            raise OperationError('attempt    to    update    a    document    not    yet    saved')
    return self._qs.filter(**self._object_key).update_one(**kwargs)
