- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 ming 中有一个映射类
from ming import Session, create_datastore
from ming import schema
from ming.odm import ODMSession
from ming.odm.mapper import MapperExtension
from ming.odm.property import ForeignIdProperty
from ming.odm.property import FieldProperty, RelationProperty
from ming.odm.declarative import MappedClass
import config
bind = create_datastore(config.DATABASE_NAME)
session = Session(bind)
odm_session = ODMSession(doc_session=session)
class Document(MappedClass):
class __mongometa__:
session = odm_session
name = 'document'
_id = FieldProperty(schema.ObjectId)
现在,我想对它做一个简单的查询
Document.query.get(_id="51e46f782b5f9411144f0efe")
但它不起作用。文档对此不是很清楚。我知道在 mongodb shell 中我们必须将 id 包装在一个 ObjectId 对象中,但我无法让它在 Python 中工作
最佳答案
您应该尝试使用 ObjectId 进行查询
from bson.objectid import ObjectId
Document.query.get(_id=ObjectId('51e46f782b5f9411144f0efe'))
裸体pymongo
from bson.objectid import ObjectId
from pymongo import Connection
connection = Connection()
db = connection['lenin']
collection = db.document
collection.find_one({'_id': '51e35ee82e3817732b7bf3c1'}) # returns None
collection.find_one({'_id': ObjectId('51e35ee82e3817732b7bf3c1')}) # returns the object
关于python - 如何通过_id在ming中查找?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17665480/
有人可以解释如何在 Ubuntu 10.0.4 (Lucid) 环境中安装 ming 吗?我一直听到关于这个软件包的真正令人惊奇的事情,但我无法正确安装它。 最佳答案 它应该很简单: sudo apt
我使用 Python 连接到 MongoDB 并使用 Ming ( http://merciless.sourceforge.net/tour.html ) 来保持数据模型的一致性。它有一些我非常喜欢
安装 Ming 0.3.2 后,我通过运行以下代码测试了安装情况: >>> from ming.datastore import DataStore >>> bind = DataStore('mon
我已经使用 Opencv 3.7、Windows 8/10 和 QT Creator 5.12 以及 MVS C++ 编译器很长时间了,现在没有任何问题。 但是,如果我将编译器切换到 QT Mingw
我有这个短代码: public function ball() { minge.addEventListener(MouseEvent.CLIC
我正在尝试从多个 png 生成 flv 视频,但输出视频似乎已损坏,没有播放器可以播放它。 setDimension(640, 360); $img = new SWFShape(); $png =
我即将开始一个使用 Django 和 MongoDB 的项目。据我所知,有两种方法可以一起使用 Django 和 MongoDB。一种方法是 Django 的分支,称为 Django-nonrel,它
我是一名优秀的程序员,十分优秀!