How to share/ensure connections are closed in Flask + mongo (pymongo) in Vercel serverless functions?

Solution
def get_db_client(host=MONGO_URL, port=27017):
        client = MongoClient(host=host
        return client
@app.route('/orders')
def get_orders():
    client = None
    try:
        client = get_db_client()
        db = client["orders_database"]
        order_id = int(request.args.get('order_id'))
        cursor = db.orders_tb.find({"order_id": order_id})
    except:
        # Some exception handling
        pass
    finally:
        if type(client)==MongoClient:
            client.close()
        return jsonify({"result": list(cursor)})