问题描述:

This question already has an answer here:

  • Why Mongoose doesn't validate on update?

    2 answers

网友答案:

you need to use $set on update

Try this:

Model.findByIdAndUpdate(req.params.id, {'$set' : req.body}, 
    {new:true, select: defaultProjection}, function( err, contact ){

if( err ) {
  res.status(422).json( err );
}
else {
  res.status(200).json( contact );
}
相关阅读:
Top