【发布时间】:2021-06-27 01:26:37
【问题描述】:
在 mongoose 模式中间件中,有 pre hooks 和 post hooks。如果我使用“保存”中间件,我可以传递选项并访问 pre hook 中的那些 optinos
//in controller
const doc = new someSchema({name:"Jeff"})
doc.save({someOption:true})
----
someSchema.pre('save',function(next,opts){
console.log(opts) // logs {someOption:true} along with all doc options
}
我希望能够使用在保存时触发的 post hook 做同样的事情,但我找不到访问这些选项的方法
someSchema.post('save',function(doc,next){
// How do i access the options? I can't find them anywhere
//if i log the doc, i only get the actual doc data, in this case name:jeff,
// is there a way to also see all of the getters and options if i log it?
}
【问题讨论】:
标签: node.js mongoose schema hook middleware