Sample Documents:
{
_id: ObjectId('4f442120eb03305789000000'),
time: ISODate("2013-10-10T20:55:36Z"),
value:1
},
{
_id: ObjectId('4f442120eb03305789000001'),
time: ISODate("2013-10-10T28:43:16Z"),
value:2
},
{
_id: ObjectId('4f442120eb03305789000002'),
time: ISODate("2013-10-11T27:12:66Z"),
value:3
},
{
_id: ObjectId('4f442120eb03305789000003'),
time: ISODate("2013-10-11T10:15:38Z"),
value:4
},
{
_id: ObjectId('4f442120eb03305789000004'),
time: ISODate("2013-10-12T26:15:38Z"),
value:5
}
It's easy to get the aggregated results that is grouped by date.
But what I want is to query results that returns a running total
of the aggregation, like:
{
time: "2013-10-10"
total: 3,
runningTotal: 3
},
{
time: "2013-10-11"
total: 7,
runningTotal: 10
},
{
time: "2013-10-12"
total: 5,
runningTotal: 15
}
Is this possible with the MongoDB Aggregation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…