How to Check "invalid numbers" Validations in mongoose? Is there any special method or keyword available? Model.js given below?
Model.js
const Schema = mongoose.Schema;
const userSchema = new Schema({
Username: {
type: String,
required: true
},
Password: {
type: String,
required: true
}
});
userSchema.pre('save', async function (next) {
try {
const user = this;
if (!user.isModified('Password')) {
next();
}
const salt = await bcrypt.genSalt(10);
const passwordHash = await bcrypt.hash(this.Password, salt);
this.Password = passwordHash;
next();
} catch (error) {
next(error);
}
});
module.exports = User;