Mongoose - array of enum strings
You can try a custom validation?Like this
const userSchema = new Schema({ phone: { type: String, validate: { validator: function(v) { return /\d{3}-\d{3}-\d{4}/.test(v); }, message: props => `${props.value} is not a valid phone number!` }, required: [true, 'User phone number required'] }});
this is the docs:https://mongoosejs.com/docs/validation.html
Quoting: https://github.com/Automattic/mongoose/issues/6102#issuecomment-364129706
const SubStrSz = new mongoose.Schema({ value : { type : String, enum : ['qwerty', 'asdf'] } });const MySchema = new mongoose.Schema({ array: [SubStrSz] });
Using that technique you will able to validate values inside of your array.