import os
from pymongo import MongoClient
from dotenv import load_dotenv

script_dir = os.path.dirname(os.path.abspath(__file__))
env_path = os.path.join(script_dir, '..', 'rag', '.env')
load_dotenv(env_path)

def get_database():
    uri = os.getenv("MONGO_URI")
    try:
        client = MongoClient(uri)
        db = client["my_rag_app"]
        print("SUCCESS: Connected to MongoDB Atlas!")
        return db
    except Exception as e:
        print(f"ERROR: Could not connect to MongoDB: {e}")
        return None

if __name__ == "__main__":
    get_database()