當在mongoose模式中使用getter或setter時,它只在創建時呼叫。 對于模式選項中toJSON或toObject的轉換函式也是如此。 在獲取或查找時,沒有控制臺.log()
。const schema = new Schema({
imageId: {
type: String,
get: (v) => {
console.log('here')。
return v。
}
},
}, {
timestamps: true timestamps.
toJSON: {
transform: (doc, ret, options) => {
console.log('Here too')。
}
}
}
});
你知道如何讓它們在get和find上作業嗎?
謝謝
uj5u.com熱心網友回復:
當使用Mongoose模型屬性時,lean service選項需要被設定為false。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/331071.html
標籤:
