2 回答
TA贡献1757条经验 获得超7个赞
您的验证器缺少 return 语句,因此就像您返回 aPromise<void>并且这不会触发 mongo 的验证。您可以添加返回或重写您的函数,并承诺后者不太优雅。
new Promise( (resolve,reject) => {
.....
resolve(true/false);
});
TA贡献1772条经验 获得超5个赞
你能试试这段代码吗:
var questSchema = mongoose.Schema({
questCategory: {
type: mongoose.Schema.Types.ObjectId,
required: true,
validate: {
validator: async function (v) {
return await data_verificator.checkIfQuestCategoryExists(v);
},
message: (props) => `${props.value} is not a valid quest category id.`,
},
},
fulfillmentPeriod: {
type: String,
required: true,
validate: {
validator: async function (v) {
return await data_verificator.checkFulfillmentPeriod(this.questCategory, v);
},
message: (props) =>
`${props.value} is an invalid value as it violates the limitations set by the quest category.`,
},
},
})
添加回答
举报