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.`,
},
},
})
添加回答
舉報