I'm currently logging power measurements (watts) at varying intervals (between 1 and 5 seconds) to my MongoDB 2.2 (db -> monitoring -> kWh). The data within my collection is packaged as below.
{
"_id":ObjectId("5060c134f05e888e03000001"),
"reading":"power",
"watts":"549.",
"datetime":1348518196
}
I need to aggregate the information to an hourly basis, therefore sum all the watts from the start of an hour to the end and divide by the number of readings during the hour. I need to be able to push this result to a new collection within MongoDB by means of PHP. This could of course be run as a cron job, but is there is a mechanism to perform this as part of an insert?
The datetime field is a Unix timestamp.