听Mongoose Schema.pre(';remove';)

听Mongoose Schema.pre(';remove';),mongoose,mongoose-schema,Mongoose,Mongoose Schema,从中,似乎可以侦听此钩子以删除任何孤立文档。事实是我无法让这个列表器工作。使用默认方法: MySchema.pre('remove',函数( 下一个:()=>void ) { 日志('将删除项:'+此。_id); next(); }); 也可以通过将选项query设置为true (MySchema as any).pre('remove',{query:true,document:false},函数( 下一个:()=>void ) { 日志('将删除项:'+此。_id); next(); })

从中,似乎可以侦听此钩子以删除任何孤立文档。事实是我无法让这个列表器工作。使用默认方法:

MySchema.pre('remove',函数(
下一个:()=>void
) {
日志('将删除项:'+此。_id);
next();
});
也可以通过将选项
query
设置为
true

(MySchema as any).pre('remove',{query:true,document:false},函数(
下一个:()=>void
) {
日志('将删除项:'+此。_id);
next();
});
请注意,要删除文档,我使用了
model.findbyiandremove()
,但我也尝试了使用
doc.remove()

const doc=wait model.findById(id);
文档删除(()=>{
日志(“删除的文档”);
});
我的版本是
5.7.13
。我错过了什么?谢谢

pre('remove',{query:true,document:false})
是for,而不是
findbyidorrove()
document#remove()

wait model.remove({u id:id});