const db = require('../db');
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({ unikey: this.unikey }, { recognitionID :  this._id + '' });
};

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

async function task () {
  const recognition =  await db.getCollection('recognition')
  const arrs = await recognition.mapReduce(map, reduce, { query: {}, out: { inline : 1 } } );
  arrs.forEach( x => {
  	if(typeof x.value.recognitionID === 'object' ) {
  		console.dir(x.value.recognitionID)
  	}
  })
}
task();

