Spaces:
Configuration error
Configuration error
Download backend/app/database/mongo.py from spoodermon/gmail-agentic: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/spoodermon/gmail-agentic/resolve/main/backend/app/database/mongo.py
- Command line
-
hf download hf://spaces/spoodermon/gmail-agentic/backend/app/database/mongo.py
-
curl -L -o mongo.py https://huggingface.co/spaces/spoodermon/gmail-agentic/resolve/main/backend/app/database/mongo.py
1.15 kB
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from app.config import settings | |
| class MongoDB: | |
| client: AsyncIOMotorClient = None | |
| db = None | |
| def connect(self) -> None: | |
| """Establish MongoDB connection client.""" | |
| self.client = AsyncIOMotorClient(settings.MONGODB_URI) | |
| self.db = self.client[settings.MONGODB_DB] | |
| def disconnect(self) -> None: | |
| """Close MongoDB connection client.""" | |
| if self.client: | |
| self.client.close() | |
| def email_bodies(self): | |
| return self.db["email_bodies"] | |
| def agent_memory(self): | |
| return self.db["agent_memory"] | |
| def agent_logs(self): | |
| return self.db["agent_logs"] | |
| # Global MongoDB wrapper | |
| mongo_db = MongoDB() | |
| async def init_mongo() -> None: | |
| """Initialize collections and indexes.""" | |
| mongo_db.connect() | |
| # Create indexes for high performance querying | |
| await mongo_db.email_bodies.create_index("email_id", unique=True) | |
| await mongo_db.agent_memory.create_index([("user_id", 1), ("email_id", 1)]) | |
| await mongo_db.agent_logs.create_index([("run_id", 1), ("step", 1)]) | |