My check:
LocationSchema.path('code').validate(function(code) {
return code.length === 2;
}, 'Location code must be 2 characters');
since I want to ensure that codethere are always 2 characters.
In my scheme, I have:
var LocationSchema = new Schema({
code: {
type: String,
trim: true,
uppercase: true,
required: true,
},
I get an error: Uncaught TypeError: Cannot read property 'length' of undefinedhowever, when my code works. Any thoughts?
source
share