所以我在mongoose中更新用户子文档的属性,但它没有保存到我的数据库中.
这是我的功能:
@User.findOne({'email': email}, (err, user) -> if err? callback(err) else if user? for account in user['accounts'] if account['account_uuid'] is account_uuid account.state = "Verified" user.save((err, updated_user, numberTouched) -> if err? console.log err return callback(err) else console.log 'Successfully verified account' console.log updated_user return callback(null, 'Successfully verified account') ) return callback(new Error('No account for account_uuid')) )
真正令人沮丧的是,updated_user
返回account.state
属性为"已验证",numberTouched
变量返回为1,表示1文档已受到保存的影响.但是当我在我的数据库中检查用户文档时,它仍然是默认值"待定".
有什么想法吗?
PS我正在使用MongoLab的开发数据库.但我认为问题不在他们身上,因为我可以更新其他属性.