In Mongoose, validation is set at the schema level. Remember how in our userSchema
we have this for the email
field:
email: { type: String, unique: true }
The unique: true
part is a type of validation that Mongoose passes directly through to MongoDB. The other types of validation we are about to look at are set in the same place, but are handled by Mongoose before it goes anywhere near the database; unless of course, you have a type of validation where you specifically choose to check against something in the database.