I am using pymongo driver. Supposedly, one can use a string to query the _id field of a document, like this:
thing = db.things.find_one({\'_id\':\'4ea113d6b6848
PyMongo has changed its structure. ObjectID
is no longer imported from pymongo
, but from bson
. It should now be:
from bson.objectid import ObjectId
thing = db.things.find_one({'_id': ObjectId('4ea113d6b684853c8e000001')})
As a reminder, per pypi/pymongo, do not install the “bson” package. PyMongo comes with its own bson package; doing “pip install bson” installs a third-party package that is incompatible with PyMongo.