mirror of
https://github.com/SirBlobby/Hoya26.git
synced 2026-02-03 19:24:34 -05:00
21 lines
585 B
Python
21 lines
585 B
Python
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 () |