Types of mongoose validation
In Mongoose there are two types of validation:
- Built-in validation
- Custom validation
To get a better understanding of how built-in validators work, let’s look at the following:
Mongoose Validation
Mongoose is a MongoDB object modeling and handling for a node.js environment. Mongoose Validation is essentially a customizable middleware that gets defined inside the SchemaType of Mongoose schema. It automatically fires off before a document is saved in the NoSQL DB. Validation can also be run manually using doc.validate(callback) or doc.validateSync() methods. Let’s understand more about this with the help of some examples.