In the collection, time stamp field is stored as a string.
{
"_id" : ObjectId("59a780a3da2100974a36cdca"),
"datetime" : "2016-08-17 0:59"
...
}
I am tring to convert the string to date in the first stage of Mongo aggregation piple line.
db.collection.aggregate([
{
$addFields: {
ts: new Date('$datetime')
}
}
])
I have done this outside the pipeline, which works fine.
{
"_id" : ObjectId("59a780a3da2100974a36cdca"),
"datetime" : "2016-08-17 0:59",
"ts" : ISODate("2016-08-17T00:59:00.000-04:00"),
}
However, if I do this inside aggregation. I got the following
{
"_id" : ObjectId("59a780a3da2100974a36cdca"),
"datetime" : "2016-08-17 0:59",
"ts" : ISODate("1969-12-31T19:00:00.000-05:00")
}