MongoKit的可调用对象没有属性'find_and_modify'

时间:2012-10-29 09:11:58

标签: python pymongo mongokit

我使用MongoKit作为ODM框架。我有对象用户:

class User(Document):
    __collection__ = 'users'
    ...

这里没有__database__ - 我使用的是不同的,取决于当前的配置文件(开发,测试等)我使用这样的查询来访问数据:

app.db.User.one({'email_confirmation_token.hex': token_hex})

工作正常。现在我需要使用find_and_modify命令。根据{{​​3}},我应该从集合中调用此方法来获取dict或从object获取对象。

此通话有效:

app.db.users.find_and_modify({'email_confirmation_token.hex': token_hex}, {'$set': {'active': True}})

但是 - 不 - :

app.db.User.find_and_modify({'email_confirmation_token.hex': token_hex}, {'$set': {'active': True}})

错误消息是: AttributeError:'CallableUser'对象没有属性'find_and_modify'

为什么它不包含此属性?

1 个答案:

答案 0 :(得分:1)

尽管有文档记录,但源代码中缺少

find_and_modify()。试试这个:

app.db.User.collection.find_and_modify({'email_confirmation_token.hex': token_hex}, {'$set': {'active': True}})
相关问题