MongoDB Aggregation Pipeline : conditionnal multiplication
how about this? it converts the number to date the multiple 1000 was to convert seconds to milliseconds
db.topic_scorings.aggregate(
[
{
$project:
{
status: 1,
newDateField:
{
//$cond: [ { "$eq": [ "$status", "submitted" ] }, "$updated_at", { $convert : { input: "$updated_at", to: "long" } } ]
//$cond: [ { "$eq": [ "$status", "submitted" ] }, "$updated_at", { $toDate : { $convert : { input: "$updated_at", to: "long" } } }]
$cond: [
{ "$eq": [ "$status", "submitted" ] },
"$updated_at",
{ $toDate : { $multiply : [ {$convert : { input: "$updated_at", to: "long" } }, 1000 ] } }
]
}
}
}
]
)