How do I pass application context to a child function in flask?

Solution
from flask import g
from pymongo import MongoClient

# import main flask app
from X import app

mongo_db = 'mongo_db'

def get_mongo_db():
    """Function will create a connection to mongo db for the current Request

    Returns:
        mongo_db: THe connection to Mongo Db
    """
    # if circular dependency error try importing app here
    from X import app
    with app.app_context():
        if mongo_db not in g:
            print('New Connection Created for mongo db')
            mongo_client = MongoClient('the_url')

            # Store the Client
            g.mongo_db = mongo_client
        else:
            print('Old Connection reused for mongo db')
        # Return The db
        return g.mongo_db['db_name']