'Apply updates given in update_spec to the document whose id
matches that of doc.'

@wrap_exceptions
def update(self, document_id, update_spec, namespace, timestamp):

    (db, coll) = self._db_and_collection(namespace)
    meta_collection_name = self._get_meta_collection(namespace)
    self.meta_database[meta_collection_name].replace_one({self.id_field: document_id, 'ns': namespace}, {self.id_field: document_id, '_ts': timestamp, 'ns': namespace}, upsert=True)
    no_obj_error = 'No    matching    object    found'
    updated = self.mongo[db].command(SON([('findAndModify', coll), ('query', {'_id': document_id}), ('update', update_spec), ('new', True)]), allowable_errors=[no_obj_error])['value']
    return updated
