Use $dateToParts y su equivalente $dateFromParts
Aquí hay un Playground actualizado
Lo que hace es básicamente dividir la fecha en sus partes:
{
$project: {
dateHour: {
$dateToParts: {
date: "$updatedAt"
}
}
}
}
produciría:
{
"dateHour": {
"day": 19,
"hour": 18,
"millisecond": 0,
"minute": 21,
"month": 3,
"second": 5,
"year": 2020
}
}
y luego reconstruyes la fecha a partir de sus partes:
{
$project: {
reconstructedDateHour: {
$dateFromParts: {
year: "$dateHour.year",
month: "$dateHour.month",
day: "$dateHour.day",
hour: "$dateHour.hour"
}
}
}
}