如何在mongoengine中按oid搜索文档 [英] How to search document by oid in mongoengine

查看:95
本文介绍了如何在mongoengine中按oid搜索文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过oid从db获取文档,例如:

I need get documents from db by oid, like:

Docs.objects(_id='4f4381f4e779897a2c000009')

但是怎么做,如果_id需要ObjectId对象,甚至我尝试从pymongo设置ObjectId也不起作用.

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'))

返回空列表

推荐答案

仅使用原始字符串怎么样?

How about just using the raw string:

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

那可能是最简单的方法了……对吗?

That is probably the easiest way ... right ?

这篇关于如何在mongoengine中按oid搜索文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆