let map = function() {
  var d = new Date(this.startTime + 8 * 60 * 60 * 1000);
  var doub = function(num) {
    if ( num <= 9 ) return "0" + num;
    else return num;
  }
  emit(d.getFullYear() + '' + doub(d.getMonth() + 1)   + '' + doub(d.getDate()), { sum: 1 });
};

let reduce = function(k, vals) {
  var result = { sum: 0 };
  for(var i in vals) {
    result.sum += vals[i].sum;
  }
  return result;
};

module.exports = async function (query) {
  return db.collection('callTask').mapReduce(map, reduce, { query, out: { inline : 1 } } );
}