• backend,  Programming

    Adding custom validators in MongoDB+Mongoose

    Today we’re going to add custom validators to some of our documents in Mongoose. Things you’ll have to be familiar with for this article MongoDB Mongoose Nodejs Why make custom validators? When dealing with data sent over the web we often find that the inputs we are given tend to be suboptimal. We need some way of relaying to our end users that they’re not meeting our input needs. This is where validators come in. We can define a function that will arbitrate what is and isn’t an acceptable input for a given field. To get started properly let’s define a model and give it a few fields. Now that…