cygnus_server / database.py
HPirela's picture
new changes
e9fe174
Raw History Blame Contribute Delete
1.18 kB
import os
from dotenv import load_dotenv
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
load_dotenv()
client = None
def get_mongo_client() -> MongoClient:
global client
if client is None:
password = os.getenv("PASSWORD")
uri = f"mongodb+srv://DDR:{password}@cluster0.o7h6s.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
client = MongoClient(uri, server_api=ServerApi('1'), uuidRepresentation='standard')
try:
client.admin.command('ping')
print("Pinged your deployment. You successfully connected to MongoDB!")
except Exception as e:
print(e)
return client
# Max concurrency used for extracting content from documents.
# A long document is broken into smaller chunks this controls
# how many chunks are processed concurrently.
MAX_CONCURRENCY = int(os.getenv("MAX_CONCURRENCY", 1))
# Max number of chunks to process per documents
# When a long document is split into chunks, this controls
# how many of those chunks will be processed.
# Set to 0 or negative to disable the max chunks limit.
MAX_CHUNKS = int(os.getenv("MAX_CHUNKS", -1))