How does validation work in Mongoose, and is it enough?
Model answer
Schema validators such as required, min, maxlength, enum and match run on save, and with runValidators on updates. They protect data shape, but they are not a substitute for validating request input in the API, and unique is an index, not a validator, so also handle the duplicate key error (code 11000).
Learn this topic
Connect Express to MongoDB with Mongoose in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.
Sign in to add your own answer.