当前位置: 动力学知识库 > 问答 > 编程问答 >

node.js - Moongoose require:true does not seem to work?

问题描述:

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 );
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: