{ "module": "mongo_ops.connection", "content": { "path": "mongo_ops.connection", "docstring": "MongoDB connection management.", "objects": { "asynccontextmanager": { "name": "asynccontextmanager", "kind": "alias", "path": "mongo_ops.connection.asynccontextmanager", "signature": "", "docstring": null }, "Optional": { "name": "Optional", "kind": "alias", "path": "mongo_ops.connection.Optional", "signature": "", "docstring": null }, "AsyncIOMotorClient": { "name": "AsyncIOMotorClient", "kind": "alias", "path": "mongo_ops.connection.AsyncIOMotorClient", "signature": "", "docstring": null }, "AsyncIOMotorDatabase": { "name": "AsyncIOMotorDatabase", "kind": "alias", "path": "mongo_ops.connection.AsyncIOMotorDatabase", "signature": "", "docstring": null }, "MongoConnectionManager": { "name": "MongoConnectionManager", "kind": "class", "path": "mongo_ops.connection.MongoConnectionManager", "signature": "", "docstring": "Manages MongoDB connections with async lifecycle.\n\nThis class provides a singleton-like manager for the MongoDB client and \ndatabase instances, ensuring they are properly initialized and closed \nacross the application lifecycle.", "members": { "connect": { "name": "connect", "kind": "function", "path": "mongo_ops.connection.MongoConnectionManager.connect", "signature": "", "docstring": "Connect to MongoDB and initialize the shared client.\n\nArgs:\n uri: MongoDB connection URI (e.g., \"mongodb://localhost:27017\").\n db_name: Name of the database to use.\n **kwargs: Additional Motor client options (e.g., maxPoolSize).\n\nReturns:\n AsyncIOMotorDatabase: The initialized database instance." }, "disconnect": { "name": "disconnect", "kind": "function", "path": "mongo_ops.connection.MongoConnectionManager.disconnect", "signature": "", "docstring": "Close the active MongoDB connection and cleanup resources." }, "get_database": { "name": "get_database", "kind": "function", "path": "mongo_ops.connection.MongoConnectionManager.get_database", "signature": "", "docstring": "Retrieve the current database instance.\n\nReturns:\n AsyncIOMotorDatabase: The active database instance.\n\nRaises:\n RuntimeError: If connect() has not been called yet." }, "get_client": { "name": "get_client", "kind": "function", "path": "mongo_ops.connection.MongoConnectionManager.get_client", "signature": "", "docstring": "Retrieve the current client instance.\n\nReturns:\n AsyncIOMotorClient: The active Motor client instance.\n\nRaises:\n RuntimeError: If connect() has not been called yet." }, "lifespan": { "name": "lifespan", "kind": "function", "path": "mongo_ops.connection.MongoConnectionManager.lifespan", "signature": "", "docstring": "Async context manager for managing connection lifecycle.\n\nDesigned for use with FastAPI or other frameworks supporting \nlifespan management.\n\nArgs:\n uri: MongoDB connection URI.\n db_name: Name of the database.\n **kwargs: Additional Motor client options.\n\nYields:\n AsyncIOMotorDatabase: The active database instance.\n\nUsage:\n @asynccontextmanager\n async def lifespan(app: FastAPI):\n async with MongoConnectionManager.lifespan(uri, db_name):\n yield" } } } } } }