26 lines
769 B
Python
26 lines
769 B
Python
from infra.config.app_settings import app_settings
|
|
from beanie import init_beanie
|
|
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from app.central_storage.backend.models.models import DocumentDoc
|
|
|
|
|
|
def register(app):
|
|
app.debug = "mongo_debug"
|
|
app.title = "mongo_name"
|
|
|
|
@app.on_event("startup")
|
|
async def start_database():
|
|
await initiate_database()
|
|
|
|
|
|
async def initiate_database():
|
|
client = AsyncIOMotorClient(
|
|
app_settings.MONGODB_URI,
|
|
serverSelectionTimeoutMS=60000,
|
|
minPoolSize=5, # Minimum number of connections in the pool
|
|
maxPoolSize=20, # Maximum number of connections in the pool
|
|
)
|
|
await init_beanie(
|
|
database=client[app_settings.MONGODB_NAME], document_models=[DocumentDoc]
|
|
)
|