【发布时间】:2015-10-27 17:11:30
【问题描述】:
我正在尝试更新 pre hook 上的计数。问题是,据我所知,由于某种未知原因,findOneAndUpdate 挂钩无法访问该文档。
我想这样做:
source.pre('findOneAndUpdate', function (next) {
console.log('------------->>>>>> findOneAndUpdate: ');
this.objects = this.objects || [];
this.people = this.people || [];
this.events = this.events || [];
this.objectCount = this.objects.length;
this.peopleCount = this.people.length;
this.eventCount = this.events.length;
next();
});
但由于某种原因,钩子中的this 不是文档,它是一个看起来几乎没用的查询对象。
我错过了什么? 如何使用 pre hook 来更新 findOneAndUpdate 的计数?
【问题讨论】:
标签: mongoose