Im currently working on a MongoDB backed RESTFUL API with flask... However, Ive got a zone search query set up with find_one(), however as soon as I try making it a larger query with multiple results using find(), I get the following error on postman :
UnboundLocalError: local variable 'output' referenced before assignment
this is the code that works, however it only returns one document from the query:
@app.route('/active_jobs/<zone>', methods = ['GET'])
def get_one_zone(zone):
ajobs = mongo.db.ajobs
q = ajobs.find_One({'zone' : zone})
output = {}
output = ({
'zone': q['zone'], 'jobdate' : q['jobdate'],
'jobtime' : q['jobtime'],'client': q['client'],
})
return jsonify({output})
once I try to chage to get all results making it find() it doesnt work
@app.route('/active_jobs/<zone>', methods = ['GET'])
def get_one_zone(zone):
ajobs = mongo.db.ajobs
q = ajobs.find({'zone' : zone})
output = {}
output = ({
'zone': q['zone'], 'jobdate' : q['jobdate'],
'jobtime' : q['jobtime'],'client': q['client'],
})
return jsonify({output})
Ps. Im a total newbie in the programming world so if you could use simple examples that would be much appreciated.