How to search document by oid in mongoengine

Denis picture Denis · Apr 3, 2012 · Viewed 17.5k times · Source

I need get documents from db by oid, like:

Docs.objects(_id='4f4381f4e779897a2c000009')

But how to do it, if _id requires ObjectId object and even I try to set ObjectId from pymongo it doesn't work.

Docs.objects(_id=pymongo.objectid.ObjectId('4f4381f4e779897a2c000009'))

return empty list

Answer

Ross picture Ross · Apr 3, 2012

This should work:

Docs.objects(pk='4f4381f4e779897a2c000009')