Query I made:
db.attendancesHistories.aggregate([
{
$match : { "date": { $gte:ISODate("2022-01-01"), $lt:ISODate("2022-12-31") } }
},
{
"$group":
{
"_id":
{
status : "$status"
},
"count":{"$sum": 1}
}
}
]);
Result:
{
"_id" : {
"status" : "ABERTO"
},
"count" : 23712.0
}
{
"_id" : {
"status" : "CONCLUIDO"
},
"count" : 507.0
}
But when I change the date period and there is no order completed, it brings it like this
{
"_id" : {
"status" : "ABERTO"
},
"count" : 100.0
}
Is there any way when you don’t have status in that period it brings the status only to zero?
Example:
{
"_id" : {
"status" : "ABERTO"
},
"count" : 100
}
{
"_id" : {
"status" : "CONCLUIDO"
},
"count" : 0
}
and is there a way to bring the total also by adding the 2 counts in a line below?
Thanks!!