def update(self, book_id: str, book: Book): updated_result = self.collection.update_one( {"_id": ObjectId(book_id)}, {"$set": book.dict(exclude_unset=True)}) if updated_result.modified_count == 0: raise NoBookUpdateError return book_id
def create(self, book: Book): inserted_result = self.collection.insert_one( book.dict(exclude_unset=True)) inserted_id = str(inserted_result.inserted_id) return inserted_id