Possibility to use filter parameters in later stages
We use embedded charts with aggregate queries for comparison of multiple date values. In our case, we are in conversations, we want to know for a certain week how many conversations were started and how many finished.
We do this book filtering on $or for the startdate to be in range OR the finished date to be in range. This works well. The problem is that later on, for instance in my aggregate query I would like to use the filter values pushed in by the embed URL, for instance in $group or $facet stages.
Suggestion : make the filter values usable in later stages by making them callable using $$filterval1, $$filterval2, and so on.
-
Arnold commented
Hi Tom, that sounds like a very nice solution and it's portable to other types of filters as well.
-
AdminTom (Admin, MongoDB) commented
Thanks for the suggestion Arnold! We're looking at how best to handle this scenario.
Rather than tie it to filters, we were thinking of adding a new method to the SDK that would let you do something like:
chart.setField("startDate", new Date("2020-09-07"))This would result in the requested value being added early in the agg pipeline for each document, i.e. with:
{ $addFields: { startDate: ISODate("2020-09-07") } }Then if you wanted to leverage it in your own query, you could simply refer to "$startDate" and it would contain the value set from the code.
Let me know if you think this will work.