mongooseexpress-validator

What is the difference between mongoose validation and using express-validator


Based on my own knowledge, you can do almost every validation in mongoose schema that you can do with express-validator. So pls can I just use mongoose or there are situation that I will need to use express-validator too even if I only create new documents


Solution

  • Indeed, you can do almost every validation in your mongoose schema like you can do using express-validator. Mongoose now supports validation on update as well, so you are good to go.

    Let me point out two cases:

    In conclusion, both methods can satisfy your validation rules. In my opinion, go with Exspress-validator for cleaner and more organised code, as well as for better and more safe code execution flow.