Where to validate in Express.js project – Validation at the database layer (re. Mongoose)? Where to validate in Express.js project – Validation at the database layer (re. Mongoose)? mongoose mongoose

Where to validate in Express.js project – Validation at the database layer (re. Mongoose)?


I would consider moving the validation logic to the Model but stop thinking of the Model as the database. The model is greater than the database. The model performs the validation, and if the validation passes it saves the data to the database, if the validation fails it returns the correct messages so that a router can render the proper error messages.