Saturday 6 May 2017

Mongoose Model.findOneAndUpdate

I'm a bit stuck using the Model.findOneAndUpdate() function from Mongoose.

I tried this

module.exports.verifyUser = function(username, callback){
  var query = {username: username};
  User.findOneAndUpdate(query, { $set: { verify: true }}, {new: true}, callback);
};

But I can't seem to update the "verify" field which is made as a boolean in the schema here

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
  }
});

If you can point me in the right direction, I'd appreciate it!



via A. Angee

No comments:

Post a Comment