Accessing a variable field within mongoDb $match aggregation pipeline

110 views Asked by At

I'm trying to dynamically filter some data via an aggregation, passing the column and the date as a parameter into the aggregation.

{"$match":
    {"\"$$dateFilter.column\"": {"$gte": "ISODate(\"$$dateFilter.value\")"}}
}

And this is how I call the aggregation (via RestHeart HTTP call) :

https://<server>/<collection>/_aggrs/<aggregationUri>?np&avars={ "dateFilter": {"column": "startDateTime", "value": "2020-12-01T00:00:00.0Z"}}

It doesn't throw an error but doesn't return any information. Any ideas ?

1

There are 1 answers

0
Andrea Di Cesare On

in RESTHeart you need to use json representation of json

dates are represented as {"$date": <epoch_time_millis>}

try something like:

https://<server>/<collection>/_aggrs/<aggregationUri>?np&avars={"dateFilter": { "column": "startDateTime", "value": {"$date": 1605135600000 }}}

1605135600000 is the epoch time (in milliseconds) of 2020-12-01T00:00:00.0Z