我使用Mongoose的Model.findOneAndUpdate()函数时有点困惑。
我试过这个
module.exports.verifyUser = function(username, callback){
var query = {username: username};
User.findOneAndUpdate(query, { $set: { verify: true }}, {new: true}, callback);
};
但我似乎无法更新“验证”字段,该字段在此处的架构中作为布尔值
var userSchema = mongoose.Schema({
name: {
type: String
},
email:{
type: String,
required: true
},
username: {
type: String,
required: true
},
password: {
type: String,
required: true
},
verify: {
type: Boolean,
required: true
}
});
如果你能指出我正确的方向,我会很感激!
答案 0 :(得分:0)
var query = {username: username.username}; // This sets it to the object field
不
var query = {username: username}; // This sets it to the object