猫鼬自定义验证器仅在第二次尝试时给出错误,这是我的代码:
const fromTimeRegex = new RegExp('([01]?[0-9]|2[0-3]):[0-5][0-9]', 'g');
...
const fromSchema = new mongoose.Schema({
from: {
type: String,
validate: {
validator: v => fromTimeRegex.test(v),
message: props => `${props.value} is not a valid!`,
},
required: true,
},
});
...
const schema = new mongoose.Schema({
receptionHours: {
type: fromSchema,
required: true,
},
});
...
即使我发送不正确的数据,第一个发布请求也会通过,但是如果我第二次发送相同的请求,它将引发异常。为什么?我该如何解决?