I'm trying to do the classic thing of making sure a user's username is not the same as their password, in Nodejs/Mongoose.
I was thinking it'd be good to use a seperate validation function, but I can't work out how to do it.
So far I've used the model code from Alex Young's Notepad tutorial. He creates a virtual password
property which I've re-used.
I've got basic validation as follows:
function validatePresenceOf(value) {
return value && value.length;
}
User = new Schema({
'username': {
type: String,
validate: [
validatePresenceOf, 'a username is required',
],
index: { unique: true }
},
});
How would I allow a validator to access other properties?