Spaces:
Runtime error
Runtime error
File size: 647 Bytes
37e46db | 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 | import os
import sys
from dotenv import load_dotenv
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from src.exception import CustomException
load_dotenv()
uri = os.getenv('CLUSTER_URI')
try:
client = MongoClient(uri, server_api=ServerApi('1'))
client.admin.command('ping')
except Exception as e:
raise CustomException(e, sys)
def dataloader(db, collection, query={}, proj={}):
db = client[db]
collection = db[collection]
try:
records = collection.find(query, proj)
return records
except Exception as e:
raise CustomException(e, sys)
|