def update(self, notice: Notice): assert notice.is_empty() == False # 存在则更新,不存在则新建 self.collection.update_one({'nid': notice.nid}, {'$set': notice.to_dict()}, upsert=True)
def add(self, notice: Notice): # self.collection.insert_one(notice.to_dict()) assert notice.is_empty() == False self.update(notice)