I'm trying to get a simple date-filtered aggregation working.
I have documents like:
{
"name" : "Article 1",
"expires" : <some date [type:datetime]>
},
{
"name" : "Article 1",
"expires" : <some other date [type:datetime]>
},
...
I'm trying to query them with an aggregate pipeline over a call from javascript, so my pipeline is passing over as JSON.
I want to get all unexpired documents, but I haven't found a way to use the $$NOW variable that works for me.
var pipeline = [
{'$sort' : {[name] : 1}},
{ "$match": {
"expires": {"$gt": "$$NOW"}
}
}
];
await myGetData(collection, pipeline).then(resp => ...
I've also tried variations of $dateFromString without any success. This should be simple, so I assume I'm doing something dumb.
The issue seems to be getting the correct date format into the pipeline JSON. From other stackoverflow questions, it seems that it needs to be a data object for comparison? Not sure how to describe that in the JSON though.
Could someone please point me in the right direction? Thanks