How to send the cursor from a mongo db find query as a result in flask

Solution
import json
from bson import ObjectId

class JSONEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, ObjectId):
            return str(o)
        return json.JSONEncoder.default(self, o)
@app.route("/stocks", methods=['GET'])
def getAllStocks():
    output = []
    all_data = stocksCollection.find({})
    for data in all_data:
        data['_id'] = json.dumps(data['_id'], cls=JSONEncoder)
        output.appned(data)
    return {"data": output}