Date() returns a string, new Date() a Date object.
As an exercise I converted the date string back to a date.
You could use this part as a project or for an update command etc… There probably is a better way to do it.
db.foo.find(
{},
{
"createdAt": {
"$toDate": {
"$reduce": {
"input": {
"$slice": [
{
"$split": [
"$createdAt",
" "
]
},
6
]
},
"initialValue": "",
"in": {
"$concat": [
"$$value",
" ",
"$$this"
]
}
}
}
}
}