eduai-backend / test_db.py
Alstears's picture
Upload 64 files
f18a082 verified
raw
history blame contribute delete
634 Bytes
from motor.motor_asyncio import AsyncIOMotorClient
import asyncio
import os
from dotenv import load_dotenv
async def test_conn():
load_dotenv()
mongo_url = os.environ.get('MONGO_URL', 'mongodb://localhost:27017')
print(f"Connecting to: {mongo_url}")
client = AsyncIOMotorClient(mongo_url, serverSelectionTimeoutMS=5000)
try:
await client.admin.command('ping')
print("✅ MongoDB Connection Successful!")
except Exception as e:
print(f"❌ MongoDB Connection Failed: {e}")
finally:
client.close()
if __name__ == "__main__":
asyncio.run(test_conn())