How to search document by oid in mongoengine

眉间皱痕 提交于 2019-12-03 13:17:24

How about just using the raw string:

Docs.objects.get(id='4f4381f4e779897a2c000009')

That is probably the easiest way ... right ?

This should work:

Docs.objects(pk='4f4381f4e779897a2c000009')

Came to this question because I had a lot of trouble with this myself. It seems like PyMongo changed this and objectid is no longer inside pymongo and is now instead:

import bson
Doc.objects.get(id=bson.objectid.ObjectId('4f4381f4e779897a2c000009'))

Also, Mongoengine uses the name 'id' for the ObjectID field.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!