from pymongo import MongoClient
"""
Establishes a connection to a MongoDB database using settings from Django's configuration.
Returns:
    db (Database): A MongoDB database instance if the connection is successful.
    None: If there is an error during the connection process.
Raises:
    Exception: If there is an error connecting to MongoDB, it will be caught and printed.
Example:
    To call this function from another module within the same app, you can use the following import statement:
    Then, you can call the function like this:
    db = get_mongo_connection()
    if db:
        # Proceed with database operations
    else:
        # Handle the connection error
"""
from django.conf import settings

def get_mongo_connection():
    try:
        client = MongoClient(settings.DATABASES["default"]["CLIENT"]["host"])
        db = client[settings.DATABASES["default"]["NAME"]]
        return db
    except Exception as e:
        print(f"Error connecting to MongoDB: {e}")
        return None
    
###