How to get the total number of subscribers from start date to current date? How to get the total number of subscribers from start date to current date? mongoose mongoose

How to get the total number of subscribers from start date to current date?


imho - having aggregation framework to have a daily sum is best what we can squeeze from mongo. As (from sql world) we don't have CTE, we cannot refer to previous document and that makes some analytics hard.

What I will do in this case is just simple forEach loop and update the sum value creating moving Sum in this particular case. This will require that data need to be sorted from oldest to newest. A sudocode for that below:

var previous = 0;forEach (var r in result){    r.count += previous;    previous = r.count;}