Spaces:
Runtime error
Runtime error
File size: 1,107 Bytes
ed0b977 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 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}")
|