rlt_salary/app/database/mongodb.py

19 lines
628 B
Python
Raw Normal View History

2024-02-27 20:21:36 +01:00
from motor.motor_asyncio import AsyncIOMotorClient
2024-02-27 23:27:42 +01:00
from app.database.MongoDBConfig import MongoDBConfig
2024-02-27 20:21:36 +01:00
class MongoDB:
2024-02-27 23:27:42 +01:00
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]