How to make a query date in mongodb using pymongo?

@Joni is correct, you need to use datetime. from datetime import datetime from pymongo import Connection # i have updated and included the complete code client = Connection(‘localhost’, 27017) db = client[‘database’] # your database name inoshare = db[‘inoshare’] # convert your date string to datetime object start = datetime(2014, 9, 24, 7, 51, 04) … Read more

Flask – Bad Request The browser (or proxy) sent a request that this server could not understand [duplicate]

The error there is resulting from a BadRequestKeyError because of access to a key that doesn’t exist in request.form. ipdb> request.form[‘u_img’] *** BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. Uploaded files are keyed under request.files and not request.form dictionary. Also, you need to lose the … Read more

Append item to MongoDB document array in PyMongo without re-insertion

You don’t need to use to retrieve the document first just use the .update method with the $push operator. def update_tags(ref, new_tag): coll.update({‘ref’: ref}, {‘$push’: {‘tags’: new_tag}}) Since update is deprecated you should use the find_one_and_update or the update_one method if you are using pymongo 2.9 or newer

JSON serializing Mongodb

The pymongo documentation you pointed is obsolete. If you’re using version 1.7 I recommend updating. With a more recent version you can do this: from bson.json_util import dumps dumps(l) https://pymongo.readthedocs.io/en/stable/api/bson/json_util.html Side answer: u’name’, u’date’, u’_id’ etc are the names of the fields of the document on the database.