2
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的外殼,我們必須包裹ID在的ObjectId對象,但我不能讓它在Python
工作