预删除事件未针对猫鼬模式触发?

Pre remove event not firing for mongoose schema?

这不是开火!不知道为什么,非常感谢这里的帮助。

 Booking.find({_id: key}).remove(function(err, result){
   if (err) { console.err("ERR", err) }
   else {
     console.log("remove result", result);
   }
 })


 BookingSchema.pre('remove', function (next) {
   console.log("THIS ID", this._id);
   next();
 });

根据 doc

There is no query hook for remove(), only for documents. If you set a 'remove' hook, it will be fired when you call myDoc.remove(), not when you call MyModel.remove().

那你可以用这个

Booking.find({_id: key}, function(err, books){
    if (err)
       throw err;
    else {
       books.forEach(function(book){
           book.remove(function(err){
              // the 'remove' pre events are emitted before this book is removed.
           });
       })
    }
});

您可以从这里获得更多信息 discussion