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()), slotID: this.slotID, pubID: this.pubID }, { number: 1 });
};

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

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