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
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b348d0-2bf16.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b348d0-2bf16.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?