I need to parse date value to specific format without using format field in dateFromString operator.
Mongo Playground
Current situation : in Mongodb 4.0 if I f
If I get the requirement right, Try the following query which uses: $dateFromParts
Input:
[
{
"date": ISODate("2020-01-16T08:54:17.604Z")
}
]
Query:
db.collection.aggregate([
{
$project: {
outputDate: {
$dateFromParts: {
"year": {
$year: "$date"
},
"month": {
$month: "$date"
},
"day": {
$dayOfMonth: "$date"
},
"hour": {
$hour: "$date"
}
}
}
}
}
]);
O/P:
[
{
"_id": ObjectId("5a934e000102030405000000"),
"outputDate": ISODate("2020-01-16T08:00:00Z")
}
]
Playground Test Link