from motor.motor_asyncio import AsyncIOMotorClient from app.database.MongoDBConfig import MongoDBConfig class MongoDB: def __init__(self, config: MongoDBConfig): self.client = AsyncIOMotorClient(config.url) self.db = self.get_db(config.db_name) self.collection = self.get_collection(config.collection) def get_db(self, db_name: str): if db_name is None: return None return self.client[db_name] def get_collection(self, collection_name: str): if collection_name is None or self.db is None: return None return self.db[collection_name]