I'm adding a series of documents to the database. Each of these documents is validated in a pre-save hook. I want Mongoose to ignore saving that particular document that fails the validation without throwing any error so that the rest of the documents that pass the validation could be saved. Here is a sample code:
schema.pre('save', function (next) {
// Validate something.
const isValidated = ...;
if (!isValidated) {
// Skip saving document silently!
}
next();
});