I’m storing aggregations for later usage. However, I cannot get $match stages with date comparisons to work. For example, our documents have a _created_at property that is stored as a date. I was attempting to build a simple pipeline that gets documents that are newer than 7 days. I tried storing the date value in the aggregation as a standard timestamp value, like this:
[ { “$match”: { _created_at: { “$gt”: 1617311291067 } } } ]
But that did not work. How can I properly store an aggregation pipeline as pure JSON so that when I use it later (without additional processing), it will work?
I can’t store a javascript Date object - 'cause that just turns it into a date string, which also did not work, for example, this did not work:
[ { “$match”: { _created_at: { “$gt”: “2021-04-01” } } } ]
But doing this in javascript did work:
[ { “$match”: { _created_at: { “$gt”: new Date(“2021-04-01”) } } } ])
Thanks,
-Chris