I want to try MongoDB for my database solution, so I'm playing around with it. The Aggregation Framework is perfect and most of the documentation explains me very well what I have to do.
My data look like this:
{ "_id" : ObjectId("54e5e79032d4796d1dec195e"),
"timestamp" : ISODate("2015-01-20T10:31:02.082Z"),
"value" : 4089 }
For example, if I want to aggregate my data per second, this is what I would do:
db.mycollection.aggregate(
{
$match : {
timestamp: {$gte: ISODate("2015-01-21T12:00:00Z"),
$lte: ISODate("2015-01-21T12:01:00Z")}
}
},
{
$group : {
_id : { $second: "$timestamp" },
averageQuantity: { $avg: "$value" },
count: { $sum: 1 }
}
}
);
My question is, what do I have to do to aggregate my data by a sample rate that's not predefined, like $second or $minute, but let's say by 30 seconds?
Using the code from my example, I would like to get 2 results returned.
Thanks in advance!