Is mongoose's validator invalid for update?

mongoose defines required, min, max and other validators in scheme, which seems to validate only the documents to be inserted by create (), but does not seem to validate the documents to be updated by update ().

if so, what is the use of this validation? Is the validator of mongoose really wrong that the document to be updated is not validated, then how to deal with the updated validation?

Mar.02,2021

document model validation is supported on the server side since MongoDB3.2. Why not just use the official plan?
https://docs.mongodb.com/manu.


mongoose also has a updateOne () update validator that triggers validation when database data is modified into save rows


  • found the answer in this article https://zhuanlan.zhihu.com/p/.
  • runValidators: null , / / perform Validation validation if the value is true,.

    model.update(conditions, doc, option, function (err, res){})
     // conditions- doc-
    *** res  {n:2, nModified:2, ok: 1} ***
    *** n nModified ok  ***
    const option = { // option
        safe: true, // 
        upsert: false, //
        multi: false,  // 
        runValidators: null, // trueValidation
        setDefaultsOnInsert: null, // upserttrue
        strict: null, // 
        overwrite: false // update-only
    }
Menu