How to write a map reduce, query with a specific range datetime and the group by clause

I have example data


{“provider”: 1, “value”: 1, “created_time”: “2014-02-11 04:33:45”}
{“provider”: 1, “value”: 2, “created_time”: “2014-02-12 04:33:45”}
{“provider”: 2, “value”: 3, “created_time”: “2014-02-13 04:33:45”}
{“provider”: 2, “value”: 2, “created_time”: “2014-02-14 04:33:45”}

How to write map reduce, query data with a specific range created_time from 2014-02-11 to 2014-02-14 and the group by provider and sum value, results like this:

  • provider: 1 value: 3
  • provider: 2 value: 5

{“rows”:[
{“key”:[1],“value”:3},
{“key”:[2],“value”:5}
]}

Can someone please help.

//MAP function(doc,meta){ emit([doc.provider,doc.created_time],1); }

//REDUCE
_sum

this keeps created_time as string ,or turn it into an array with
dateToArray(doc.created_time);

//MAP function(doc,meta){ emit([doc.provider,doc.created_time],1); }

//REDUCE
_sum

You can also dateToArray(doc.created_time); to convert date to array too.