37 lines
No EOL
1 KiB
Python
37 lines
No EOL
1 KiB
Python
#!/usr/bin/env python3
|
|
"""Test database connection."""
|
|
|
|
import asyncio
|
|
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from app.core.config import settings
|
|
|
|
async def test_db():
|
|
print("Testing database connection...")
|
|
print(f"URI: {settings.mongodb_uri}")
|
|
|
|
client = AsyncIOMotorClient(settings.mongodb_uri)
|
|
db = client[settings.mongodb_db]
|
|
|
|
# Test connection
|
|
try:
|
|
await client.admin.command('ping')
|
|
print("✅ MongoDB connection successful")
|
|
|
|
# Count users
|
|
user_count = await db.users.count_documents({})
|
|
print(f"✅ User collection accessible, found {user_count} users")
|
|
|
|
# Test finding a user
|
|
user = await db.users.find_one({"email": "admin@example.com"})
|
|
if user:
|
|
print("✅ Found admin user:", user.get('email'))
|
|
else:
|
|
print("❌ Admin user not found")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Database error: {e}")
|
|
|
|
client.close()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_db()) |