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.
![](https://secure.gravatar.com/avatar/39bbad47a8c024446b7a48010cedb8d3?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)
-
Arnold commented
Hi Tom, that sounds like a very nice solution and it's portable to other types of filters as well.
-
AdminTom (Product Manager, 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.