Initial commit - cleaned repository
This commit is contained in:
22
services/users/backend/database.py
Normal file
22
services/users/backend/database.py
Normal file
@ -0,0 +1,22 @@
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
from beanie import init_beanie
|
||||
import os
|
||||
from models import User
|
||||
|
||||
|
||||
async def init_db():
|
||||
"""Initialize database connection"""
|
||||
# Get MongoDB URL from environment
|
||||
mongodb_url = os.getenv("MONGODB_URL", "mongodb://mongodb:27017")
|
||||
db_name = os.getenv("DB_NAME", "users_db")
|
||||
|
||||
# Create Motor client
|
||||
client = AsyncIOMotorClient(mongodb_url)
|
||||
|
||||
# Initialize beanie with the User model
|
||||
await init_beanie(
|
||||
database=client[db_name],
|
||||
document_models=[User]
|
||||
)
|
||||
|
||||
print(f"Connected to MongoDB: {mongodb_url}/{db_name}")
|
||||
Reference in New Issue
Block a user