How can i access save options inside a post hook in mongoose?

Viewed 290

In mongoose schema middleware, there's pre hooks and post hook. If i use a 'save' middleware, i can pass it options and access those optinos inside the pre hook

//in controller
const doc = new someSchema({name:"Jeff"})
doc.save({someOption:true})
----
someSchema.pre('save',function(next,opts){
  console.log(opts) // logs {someOption:true} along with all doc options
}

I want to be able to do the same thing with a post hook that gets triggered also on the save, but i cant find a way to access those options

 someSchema.post('save',function(doc,next){
   // How do i access the options? I can't find them anywhere
   //if i log the doc, i only get the actual doc data, in this case name:jeff, 
  // is there a way to also see all of the getters and options if i log it?
}
1 Answers

here is how I access it (on the pre hook though):

this.$__.saveOptions
Related