Update db/mongo.py
Browse files- db/mongo.py +7 -10
db/mongo.py
CHANGED
@@ -1,25 +1,22 @@
|
|
1 |
import os
|
2 |
from motor.motor_asyncio import AsyncIOMotorClient
|
3 |
|
|
|
4 |
MONGO_URI = os.environ.get("MONGODB_URI")
|
5 |
|
6 |
-
# Extract database name from the URI manually
|
7 |
if not MONGO_URI:
|
8 |
-
raise ValueError("MONGODB_URI environment variable not set")
|
9 |
|
10 |
-
#
|
11 |
-
db_name = MONGO_URI.rsplit("/", 1)[-1].split("?")[0]
|
12 |
-
if not db_name:
|
13 |
-
raise ValueError("No default database found in MONGODB_URI")
|
14 |
-
|
15 |
-
# Initialize client
|
16 |
client = AsyncIOMotorClient(MONGO_URI)
|
17 |
-
|
|
|
|
|
18 |
|
19 |
# Collections
|
20 |
patients_collection = db["patients"]
|
21 |
results_collection = db["patient_analysis_results"]
|
22 |
|
23 |
-
# Optional
|
24 |
def get_mongo_client():
|
25 |
return client
|
|
|
1 |
import os
|
2 |
from motor.motor_asyncio import AsyncIOMotorClient
|
3 |
|
4 |
+
# MongoDB URI (must be set in Hugging Face Secrets)
|
5 |
MONGO_URI = os.environ.get("MONGODB_URI")
|
6 |
|
|
|
7 |
if not MONGO_URI:
|
8 |
+
raise ValueError("MONGODB_URI environment variable is not set.")
|
9 |
|
10 |
+
# Initialize MongoDB client
|
|
|
|
|
|
|
|
|
|
|
11 |
client = AsyncIOMotorClient(MONGO_URI)
|
12 |
+
|
13 |
+
# Use the correct database name explicitly
|
14 |
+
db = client["cps_db"]
|
15 |
|
16 |
# Collections
|
17 |
patients_collection = db["patients"]
|
18 |
results_collection = db["patient_analysis_results"]
|
19 |
|
20 |
+
# Optional utility function to reuse the client
|
21 |
def get_mongo_client():
|
22 |
return client
|