Node.js Mongoose更新后中间件不工作

Node.js Mongoose更新后中间件不工作,node.js,express,mongoose,Node.js,Express,Mongoose,我正在使用“猫鼬”:“^4.1.2”。在更新文档后,我尝试更新匹配率字段。但它也不起作用,不会抛出任何错误 以下是代码: list.model.js list.controller.js 声明schema.post('update',函数(doc,next){…})为回调签名(如果您的中间件不是异步的,但您的中间件是异步的,则带有next可选)。另外,我想知道从update中间件中调用update()是否不会带来问题。。。声明schema.post('update',函数(doc,next){…

我正在使用
“猫鼬”:“^4.1.2”
。在更新文档后,我尝试更新
匹配率
字段。但它也不起作用,不会抛出任何错误

以下是代码:

list.model.js

list.controller.js

声明
schema.post('update',函数(doc,next){…})
为回调签名(如果您的中间件不是异步的,但您的中间件是异步的,则带有
next
可选)。另外,我想知道从
update
中间件中调用
update()
是否不会带来问题。。。声明
schema.post('update',函数(doc,next){…})
为回调签名(如果您的中间件不是异步的,但您的中间件是异步的,则带有
next
可选)。另外,我想知道从
update
中间件中调用
update()
是否不会带来问题。。。
'use strict';

var mongoose = require('bluebird').promisifyAll(require('mongoose'));
import { Schema } from 'mongoose';

var ListSchema = new Schema({
  name: { type: String, required: true },
  user: { type: Schema.Types.ObjectId, ref: 'User', required: true },
  emails: [],
  emailColRef: String,
  matchCount: Number,
  totalCount: Number,
  matchRate: Number,
  state: {
    type: String,
    enum: ['pending', 'complete', 'invalid']
  },
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  },
  default: {
    type: Boolean,
    default: false
  }
});


ListSchema
  .virtual('count')
  .get(() => this.emails.length);

ListSchema
  .post('update', function() {

   //  this.update({},{ $set: { matchRate: this.matchCount / this.totalCount } });//Not working
      //////-------------OR---------------//////
   //  this.matchRate=this.matchCount / this.totalCount;//Not working

    console.log(this.matchCount);//undefined
    console.log(this.totalCount);//undefined
    console.log(this.matchRate);//undefined



  });

export default mongoose.model('List', ListSchema);
.....
.....
.....
var newList = {};
newList.name = name;
newList.emails = emails;
newList.emailColRef = emailColRef;
newList.state = status;
newList.matchCount = matchCount;
newList.totalCount = totalCount;
var query = { name: req.body.name };
List.update(query, newList, function(err, doc) {
  // index(req, res);
  if (err) {
    console.log("Error in list update ", err)
    return;
  }

  fs.unlink(req.file.path, function(err) {
    if (err) {
      console.log("Error in removing file", err)
      return;
    }
  });

  console.log('Update list with match status');
});