prod-wag-backend-automate-s.../Controllers/Mongo/implementations.py

18 lines
660 B
Python

# Initialize the MongoDB handler with your configuration
from Controllers.Mongo.database import mongo_handler
# Use the collection with automatic retry capabilities
with mongo_handler.collection("users") as users_collection:
# These operations will automatically retry on failure
users_collection.insert_one({"username": "john", "email": "john@example.com"})
# Find operations also have retry capabilities
user = users_collection.find_one({"username": "john"})
# Update operations will retry if they encounter transient errors
users_collection.update_one(
{"username": "john"}, {"$set": {"last_login": "2025-03-31"}}
)