Hello,

I have a history of operations that I need to group into buckets.

A bucket should contain all operation between a creation and deletion.

I have a aggregation pipeline that generate the boundaries of the bucket and an other one that create the bucket from the result of the previous one. This is done in java with to call to the mongo database.

What I like to have is a unique pipeline that does all this job.

I try to do this by using a $lookup after generating the boundaries and calling the $bucket operation inside the lookup pipeline.

I use the let to inject a variable that I can access on the bucket stage.

My problem is that I don’t know how to inject my wanted boundaries.
I try:

  • to set the “boundaries” : “$$wantedBoundaries”
  • using an expression ($expr): “boundaries” : { “$expr”: “$$wantedBoundaries”}
  • encapsulate all the bucket into an $expr

The documentation for the lookup indicate that the expression is mandatory only for the match.

The playground to illustrate the problem.

I am missing something or it is not possible to do that?

Thanks for your help.

Mael