So I'm using aggregation framework to sum some results in given time blocks.
My question is how do I return count: 0 every time if there was no results in the time block.
So let's say in first ten seconds my count: 7 in next ten seconds count: 2 and then if in the third time block there was nothing I would like aggregate function to return count: 0
Below simple summing operation:
$group: {
_id: 1,
count: { $sum: 1 }
}
I have tried using $ifNull, but it didn't work for me:
$group: {
_id: 1,
count: { $sum: { $ifNull: [ $count, 0 ] } }
}
Simply do this...
$group: {
_id: 1,
count: { $sum: 1 }
}
You were already on right track.