![](/img/trans.png)
[英]Because I can't run await on the top level, I have to put it into an async function - why can I then call that async function directly?
[英]Why can't I have async transformers in Mongoose?
在定義 ZCCADCDEDB567ABAE643E15DCF0974E503Z 架構時,我是否有理由不能使用異步變壓器? 這是一個例子:
const bookSchema = new Schema({
title: {
type: String,
transform: async function(v) {
return Promise.resolve(v)
}
},
});
事實證明這是不可能的,因為在同步函數的toJSON
和toObject
中調用了轉換器。 相反,使用中間件(不是那么干凈,但它可以完成工作)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.