Validators Flashcards

1
Q

What is the format for validators in a Mongoose schema?

A

validator: [val, ‘errormessage’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the most important validators in Mongoose?

A

min/max for Numbers, and min/maxlength for Strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you write a validator to ensure that a property can have only one of a certain set of string values?

A

property: {type: Datatype, enum: {values: [‘val’, ‘val’, ‘val’]}, message: ‘error message’}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you write a custom validator?

A

property: {type: datatype, validate: {validator: function(){}, message: ‘error message’ } }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What value must custom validator functions return?

A

A true or false value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the this keyword in custom validators refer to?

A

The object about to be saved

How well did you know this?
1
Not at all
2
3
4
5
Perfectly