Mongoose中间件post-`update`不工作

Mongoose中间件post-`update`不工作,mongoose,Mongoose,我用的是猫鼬4.11.3。我正在尝试使用postupdate中间件。它不起作用了。我尝试了保存一个,它工作正常。不知道怎么了 const mongoose = require('mongoose') const Schema = mongoose.Schema const ProfileSchema = Schema({ // schema defined here }) // working fine ProfileSchema.post('save', function () {

我用的是猫鼬4.11.3。我正在尝试使用post
update
中间件。它不起作用了。我尝试了
保存
一个,它工作正常。不知道怎么了

const mongoose = require('mongoose')
const Schema = mongoose.Schema

const ProfileSchema = Schema({
  // schema defined here
})

// working fine
ProfileSchema.post('save', function () {
    console.log('save called') 
})

// not working
ProfileSchema.post('update', function (err, doc, next) {
    console.log('update called') 
})
我正在调用
findOneAndUpdate
,数据正在更新,但没有调用更新中间件。甚至pre也不起作用

ProfileSchema.post('findOneAndUpdate', function () {
    console.log('pre - update')
})

提前谢谢。

这对我来说很有效,但不确定为什么
'update'
不起作用

ProfileSchema.post('findOneAndUpdate', function () {
    console.log('pre - update')
})
如果使用,则不会调用“更新”挂钩

Profile.updateOne();
Profile.findOneAndUpdate();
等等

findOneAndUpdate
”之所以有效,是因为您正在使用

Profile.findOneAndUpdate();
应该有道理