Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to always run validators mongoose

//To run it for just one query:
Schema.updateOne({}, {}, { runValidators: true })

//To run globally:
mongoose.plugin(schema => {
    schema.pre('findOneAndUpdate', setRunValidators);
    schema.pre('updateMany', setRunValidators);
    schema.pre('updateOne', setRunValidators);
    schema.pre('update', setRunValidators);
});

function setRunValidators() {
    this.setOptions({ runValidators: true });
}
Source by github.com #
 
PREVIOUS NEXT
Tagged: #run #validators #mongoose
ADD COMMENT
Topic
Name
1+7 =