These are chat archives for Automattic/mongoose

7th
Jan 2019
samicelus
@Samicelus
Jan 07 10:38
Hi, I'm using the aggregate middleware hook so I can modify the aggregate operators to do some pre lookup work every time before execution.
but I don't know how to get the parameters passed into the aggregate function
code
MySchema.pre('aggregate', () => {
  //any code here to get aggregate operators passed into aggreate(params)?
  params.unshift({
    "$lookup":{
      "from": other_model_name,
      "localField": "detail_id",
      "foreignField": "_id",
      "as": "detail"
    }
  })
})
That will be very helpful if anyone give me some example of using aggregate hook