Validators Flashcards
What is the format for validators in a Mongoose schema?
validator: [val, ‘errormessage’]
What are the most important validators in Mongoose?
min/max for Numbers, and min/maxlength for Strings
How do you write a validator to ensure that a property can have only one of a certain set of string values?
property: {type: Datatype, enum: {values: [‘val’, ‘val’, ‘val’]}, message: ‘error message’}
How do you write a custom validator?
property: {type: datatype, validate: {validator: function(){}, message: ‘error message’ } }
What value must custom validator functions return?
A true or false value
What does the this keyword in custom validators refer to?
The object about to be saved