Mongoose Model.findOneAndUpdate

时间:2017-05-06 19:47:48

标签: json node.js mongodb express mongoose

我使用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
  }
});

如果你能指出我正确的方向,我会很感激!

1 个答案:

答案 0 :(得分:0)

哈哈,我错过了什么,它应该是

var query = {username: username.username}; // This sets it to the object field

var query = {username: username}; // This sets it to the object