File size: 492 Bytes
a61504d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi


def init_mongo_db(uri: str, db_name: str):
    """Initialize the mongodb database."""

    try:
        assert uri is not None, "No URI passed"
        client = MongoClient(uri, server_api=ServerApi("1"))
        database = client[db_name]
        print("Connected to MongoDB")
        return database
    except Exception as e:
        print("Something went wrong connecting to mongodb")
        return