I some data from every hour that looks like this:
{
"high" : 4686.87,
"low" : 4671.11,
"open" : 4671.12,
"count" : 833,
"volume" : 283.194184560001,
"close" : 4678.51
}
...
{
"high" : 4735,
"low" : 4670.82,
"open" : 4734.88,
"count" : 1586,
"volume" : 405.721894079999,
"close" : 4671.12
}
...
I want to group then every 7 days (every 7 documents). Something like this:
db.getCollection('ticks').aggregate({$sort:{_id: -1}}, {$group: {
id: // every 7 docs,
open: { $first: '$open' },
close: { $last: '$close' },
high: { $max: '$high' },
low: { $min: '$low' },
volume: { $sum: '$volume' }
}});
What "id" should I use or how I add a new field that allows me to make it work?
NOTE: I know I can use the data to group it every week of the year, but don't want every week. I already have a weekly aggregated. I want to have the last 7 days aggregated, that could be spread on two weekOfYear