let map = function() {
  var d = new Date(this.updateTimestamp + 8 * 60 * 60 * 1000);
  var doub = function(num) {
    if ( num <= 9 ) return "0" + num;
    else return num;
  }
  emit({ date: d.getFullYear() + '' + doub(d.getMonth() + 1)   + '' + doub(d.getDate()),  pubID: this.accountID },, { 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('task').mapReduce(map, reduce, { query, out: { inline : 1 } } );
}