【发布时间】:2012-11-28 11:09:12
【问题描述】:
假设我有一个名为 Post 的 MongoEngine 文档类:
class Post(Document):
author = ReferenceField(Author)
如何在不获取实际作者对象的情况下获取帖子的作者 ID?
如果我写
print post.author.id
MongoEngine 对数据库进行查询以获取作者对象。我会写
print post._data["author"]
如果 author 字段已被取消引用,则返回 Author 对象,否则返回 DBRef 对象。
有这样做的标准方法吗?
【问题讨论】:
标签: python mongodb mongoengine