I am trying to apply a map reduce function in a document like this:
{
"_id": 2,
"timestamp_day": "1/20/2005 12:00:00 AM",
"variableID": "GUID",
"subscriptionID": "1",
"unit": "kWh",
"timezone": "UTC",
"sum": 0,
"numberOfRecords": 96,
"values": {
"1": 0.06232154558520836,
"2": 0.06232154558520836,
"3": 0.06232154558520836,
"4": 0.06232154558520836,
"5": 0.06232154558520836,
"6": 0.06232154558520836,
"7": 0.06232154558520836,
"8": 0.06232154558520836,
"9": 0.06232154558520836,
...
}
}
I have documents for each day I'm keeping information, and each value represents a reading. My objective is to apply a mapReduce function in this document so I can retrieve metrics like avg per day, avg per day per id, and so on. The thing is that I don't know how to do that since the values key contains a BSONElement.
So far my map function is as follows:
var mapFunction = function() {
emit(this.subscriptionID, this.values);
}
And by what I understood with this, it will be sent to reduce function all the values stored in values, but again, since it is a BSON element how can I make those calculations? A foreach going through each one? Performance is important..
Thanks in advance.