Employing async.parallel to simultaneously run 2 functions, initiated from a static function within a mongoose model. In this code snippet (where the model contains a static function named verifyParent), I utilize this
to access the model and its functions:
async.parallel([
async.apply(content, {slug: slug}),
async.apply(this.verifyParent, req.body.reply),
], (err, result) => {
//results
});
However, within the this.verifyParent function, attempting to use this
references my express app rather than the mongoose model. It seems that async.apply is causing this behavior, and I am struggling to maintain the usual value of this
.
In the verifyParent function, I am querying mongodb. When calling this.findOne()
, it returns an error stating it's not a function, which suggests that it is referencing the app rather than the model.