Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Help with Pymongo API

So the issue is the following... Im testing out the API for flask application using MongoDB with PyMongo. Im doing an app.route to make a query based on a certain date, the code looks as following:

@app.route('/active_jobs/<jobdate>', methods = ['GET']) def get_a_date(jobdate):

ajobs = mongo.db.ajobs

output = []

for q in ajobs.find({'jobdate':jobdate}):

    output.append ({
    'jobdate' : q['jobdate'], 'jobtime' : q['jobtime'],'plant': q['plant'],
    'po': q['po'], 'company': q['company'], 'client': q['client'],
    'jobaddress': q['jobaddress'], 'm3': q['m3'], 'use': q['use'],
    'formula': q['formula'], 'placement': q['placement'],
    'badmix1': q['badmix1'], 'badmix2': q['badmix2'], 'badmix3': q['badmix3'],
    'confirmation': q['confirmation'],'status': q['status']
    })

return jsonify({'result' : output})

Postman does not mark any errors, it just displays an empty 'result' json object.

Now I believe the issue has something to do with the date object format, because if I do the following query in the mongo shell with quotation marks wrapped around the date, it gives me back the results as expected:

db.ajobs.find({'jobdate': "2016-09-08"})

Any help would be much appreciated.

Note: all of the query structure has worked flawlessly, up until this point. Hence why I believe the issue is with the date object.

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Alejandro;

Did you get this issue resolved?

Ken

No, truth is Ive searched everywhere, with no luck.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Any chance you can give me an update on the problem and I'll see what I can do to help you out? Maybe include a link to your project's GitHub repo, if it exists.

Thanks,
Ken

Very kind of you, I stopped working on that flask pymongo api, when I lost all hope. However, Im currently undergoing the django track to see if I can somehow find a workaround. Truth is, Im a little embarrassed about that flask app. I started it very early and has way too many buggs. I'm starting fresh, hopefully by the time I get to the API I find a solution to this problem.

Thanks,

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Alejandro

I understand, but no reason to be embarrassed we've all been there. When/if you revisit it and want some assistance I would be happy to lend a second set of eyes on the issue.

Happy coding,
Ken