Mapreduce java script to find the avg temperture

{“temp”: 13, “city”: “london”, “date”: “201405”},
{“temp”: 15, “city”: “paris”, “date”: “201405”},
{“temp”: 12, “city”: “london”, “date”: “201405”},
{“temp”: 11, “city”: “paris”, “date”: “201505”},
{“temp”: 12, “city”: “london”, “date”: “201505”},
{“temp”: 10, “city”: “niveda”, “date”: “201505”}

I have a json object as above. I am able to find the max, min and avg temp with respect to the city. Can anyone give me an idea of how to extend this as per the month. I mean, how to find the average temp of a city with respect to month/time?

In pseudo-JS:

emit([,], doc.temp);

Make the reduce function compute an average of the values.

Query with groupLevel=2 to group each unique city/date pair together.

Thanks for the reply jens… How to achieve the following output provided the same json input…
‘rows’:[ ‘keys’:‘201405’,‘value’:{{‘city’:‘london’, ‘temp’:12 },
{‘city’:‘paris’, ‘temp’:‘15’}}
‘keys’:‘201505’,‘value’:{{‘city’:‘london’, ‘temp’:12 },
{‘city’:‘paris’, ‘temp’:‘11’},
{‘city’:‘niveda’, ‘temp’:‘10’}}
It would be really helpful if you can guide me to achieve this…