Spaces:
Runtime error
Runtime error
Update db/mongo.py
Browse files- db/mongo.py +19 -0
db/mongo.py
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import motor.motor_asyncio
|
| 2 |
+
import os
|
| 3 |
+
from fastapi import HTTPException
|
| 4 |
+
from bson.objectid import ObjectId
|
| 5 |
+
|
| 6 |
+
# Load MongoDB URI from Hugging Face Space secrets
|
| 7 |
+
MONGODB_URI = os.environ.get("MONGODB_URI")
|
| 8 |
+
if not MONGODB_URI:
|
| 9 |
+
raise HTTPException(status_code=500, detail="MONGODB_URI not set in environment")
|
| 10 |
+
|
| 11 |
+
# Create MongoDB client
|
| 12 |
+
client = motor.motor_asyncio.AsyncIOMotorClient(MONGODB_URI)
|
| 13 |
+
|
| 14 |
+
# Access the database (you can change the DB name here if needed)
|
| 15 |
+
db = client.get_default_database()
|
| 16 |
+
|
| 17 |
+
# Access collections
|
| 18 |
+
patients_collection = db["patients"]
|
| 19 |
+
|