convert pymongo cursor to json
It looks like you want to import from bson not pymongo. I believe json_util was moved to that module recently. https://pymongo.readthedocs.io/en/stable/api/bson/json_util.html
It looks like you want to import from bson not pymongo. I believe json_util was moved to that module recently. https://pymongo.readthedocs.io/en/stable/api/bson/json_util.html
So if anyone comes across this later, I was using the wrong option. What I was looking for is serverSelectionTimeoutMS
You can use: col=”my_collection” db[col].update() reference
You can use the following: collection.remove({“date”: {“$gt”: “2012-12-15”}})
@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
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
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
I recommend using mongomock for mocking mongodb. It’s basically an in-memory mongodb with pymongo interface and made specifically for this purpose. https://github.com/mongomock/mongomock
It should be : from pymongo.objectid import ObjectId thing = db.things.find_one({‘_id’: ObjectId(‘4ea113d6b684853c8e000001’) }) EDIT: The current import is: from bson.objectid import ObjectId
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.