When using built-in validations in a mongoose model, it's possible to trigger a model validation. For example if you received user inputs, and created a new instance of your model, well it's possible to make sure the models fits your needs. It's pretty convenient if you want to make sure that what you are going to insert fits your requirements without actually querying the database server.
let user = new User({username:"jack", age:38});
await user.validate();
Sources from the mongoose package documentation:
Comments
Post a Comment