Scrap-Dji / db /mongo_connector.py
joel
Initial deployment: Scrap-Dji with API
dfdddb1
raw
history blame contribute delete
516 Bytes
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