Spaces:
Runtime error
Runtime error
Download tests/debug_direct.py from Darshankumarr03/Swift-Query: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/debug_direct.py
- Command line
-
hf download hf://spaces/Darshankumarr03/Swift-Query/tests/debug_direct.py
-
curl -L -o debug_direct.py https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/debug_direct.py
1.11 kB
| import os | |
| import pymongo | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| uri = os.environ.get("MONGO_URI") | |
| if not uri: | |
| print("No MONGO_URI found") | |
| exit(1) | |
| if "mongodb.net/?" in uri: | |
| uri = uri.replace("mongodb.net/?", "mongodb.net/swiftquery?") | |
| print(f"Connecting to... {uri.split('@')[1] if '@' in uri else 'local'}") | |
| try: | |
| client = pymongo.MongoClient(uri, serverSelectionTimeoutMS=5000) | |
| db = client.get_database("swiftquery") # Explicitly get the db if URI doesn't select it impliedly | |
| # or rely on uri default | |
| if not db: | |
| # try to parse from uri (usually the default db) | |
| db = client.get_default_database() | |
| print("Connected.") | |
| print("--- Patients ---") | |
| patients = db.patient.find() | |
| for p in patients: | |
| print(f"ID: {p.get('id')} ({type(p.get('id'))}), SQL_ID: {p.get('sql_id')} ({type(p.get('sql_id'))})") | |
| print("--- History ---") | |
| hist = db.medicalhistory.find_one() | |
| if hist: | |
| print(f"Patient_ID: {hist.get('patient_id')} ({type(hist.get('patient_id'))})") | |
| except Exception as e: | |
| print(f"Error: {e}") | |