2012-10-29 36 views
0

我使用MongoKit作爲ODM框架。我有對象的用戶:MongoKit的可調用對象沒有屬性'find_and_modify'

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

沒有__database__在這裏 - 我用不同的人依賴於當前配置文件(開發,測試等),我使用查詢這樣的訪問數據:

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

它工作正常。現在我需要使用find_and_modify命令。根據documentation,我應該從集合中調用此方法來獲取字典或從對象獲取對象。

此調用工作:

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

儘管有記錄,但源代碼中仍缺少find_and_modify()。試試這個:

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