I am trying to calculate with some dates in my aggregation and $lookup
. I was first thinking of using a function within the aggregation, but JavaScript is not allowed to be used.
{
$lookup: {
from: "sales",
let: { user: "$_id" },
pipeline: [
$project: {
time: //// CALCULATE TIME DIFFERENCE BETWEEN $createdAt and $startedAt,
}
]
as: "sales"
}
}
Is there any way to return something similar to this in my $project
?
const calculate = (created, started) => {
const result = moment(created).diff(moment(started))
return result
}