Spaces:
Sleeping
Sleeping
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from utils.config import MONGO_URI, MONGO_DB | |
| client = AsyncIOMotorClient(MONGO_URI) | |
| db = client[MONGO_DB] | |
| async def save_to_mongo(collection: str, document: dict): | |
| """Sauvegarde un document de manière asynchrone dans MongoDB""" | |
| try: | |
| await db[collection].update_one( | |
| {"source_url": document["source_url"]}, | |
| {"$set": document}, | |
| upsert=True | |
| ) | |
| return True | |
| except Exception: | |
| return False |