I'm trying to see if a date is in the past in a Mongo aggregate pipeline, using Meteor / nodeJS. The pipeline has to be completely self-contained; I cannot pre-calculate any values.
The first step is to find the current date. According to the docs, I expect new Date() to return the current date as an ISO date.
But what I'm getting is:
ISODate("1970-01-01T00:00:00Z")
Data:
[
{
"_id": 1
}
]
Code:
db.collection.aggregate([
{
"$addFields": {
"now": new Date()
}
}
])
Output:
[
{
"_id": 1,
"now": ISODate("1970-01-01T00:00:00Z")
}
]
What am I doing wrong? How can I calculate the current date in my aggregate function? Many thanks for help.