I am trying to update pre hook counts. The problem is that for some unknown reason, the findOneAndUpdate quest findOneAndUpdate not have access to the document, as far as I can tell.
I would like to do this:
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(); });
But for some reason, this in hook is not a document, its Query object, which seems useless.
What am I missing? How to use a preliminary hook to update counters on findOneAndUpdate?
mongoose
Justin808
source share