I am using mongojs to do an aggregation to sum the revenue in a collection. I keep inserting new records with some revenue to db/collection, However, after a few days, I make a request to the api I created, the recent sum revenue become 0. then I switch between api params, it will show the correct sum revenue again. then I keep insert 100 records, it will show 0 revenue again by the time of the 100 records insertion. If I wanna keep the api working for few days, I have to restart the express server. I guess it may be the caching issue. however, I do not know exactly the reason. The issue exist on both development and production environment.
my aggregation looks like followings
{
$match: { type: 'chart' }
},
{
$group: {
revenue: { $sum: "$properties.USD" }
}
},
{
$group: {
revenue: { $sum: '$revenue' }
}
}