mongoose middleware issues

the scenarios are as follows

scenario #1

someSchema.pre('save', function(next){
  asyncFunction(function(){
    this.sub.value = 'something'
    next()
  })
})

This fails because this changes context and now represents asyncFunction, and so I can't modify the incoming data within a function. It comes up with an error that this.sub is not defined

scenario #2, based on the information from hooks-js

some.Schema.pre('save', function(next){
  asyncFunction(function(){
    next('something')
  });
});
some.Schema.pre('save', function(next, value){
  this.sub.value=value
  next()
})

This works, in so far as that it modifies the values, and the mongodb side is fine, however it just hangs, and never continues after saving the document.

Am I doing something wrong? is there a better way of doing this? Or is this a bug

scenario #3 originally failed but now seems to work

someSchema.pre('save', function(next){
  x = this
  asyncFunction(function(){
    x.sub.value = 'something'
    next()
  })
})

That said, I am still curious as to why scenario #2 didn't work.

In the first scenario you need to capture the original this context you want to make available to the callback like this:

someSchema.pre('save', function(next){
  var self = this;
  asyncFunction(function(){
    self.sub.value = 'something'
    next()
  })
})

In the second scenario I think you're a bit off in the weeds. You can't pass values from one middleware function to next via parameters. When you use the two parameter callback version of the middleware you're marking it as parallel middleware and the second parameter is the done function that must be called when the callback is done with its processing.