@classmethod
def update(cls, spec, document, upsert=False):
    """
        Mimics a subset of PyMongo's Collection.update functionality. The spec
        is used to search for the document to update, document contains the
        values to be updated, and upsert specifies whether to do an insert if
        the original document is not found.
        """
    previous = cls.get(**spec)
    cls.pre_save.send(previous)
    result = cls.c.update(spec, document, upsert=upsert)
    current = cls.get(**spec)
    cls.post_save.send(current)
    return result
