I have a view whereby key is the date (as I would like to query by date) and the value is an object with two pieces of information i.e.:
  {
    key: [ 2021, 4, 23 ],
    value: { 
             vimr: '7b715c70-2689-4241-a07e-450c8aebf27c', 
             prod: '392799267' 
    }
  },
  {
    key: [ 2021, 6, 17 ],
    value: { 
             vimr: '4845a8f6-39c8-419e-9b22-1c1bc7ef432b', 
             prod: '768298103' 
    }
  },
  {
    key: [ 2021, 6, 17 ],
    value: { 
             vimr: '7b715c70-2689-4241-a07e-450c8aebf27c', 
             prod: '768298103' 
    }
  },
  {
    key: [ 2021, 4, 2 ],
    value: { 
             vimr: '7b715c70-2689-4241-a07e-450c8aebf27c', 
             prod: '392799267' 
    }
  }
I'm looking to reduce this information to remove duplicates and minimise the amount of data that is returned from a query. Looking at the documentation, it seems the input for the values parameter to the reduce function is an array like so:
  [
     { 
         vimr: '7b715c70-2689-4241-a07e-450c8aebf27c', 
         prod: '392799267' }
     },
     { 
         vimr: '4845a8f6-39c8-419e-9b22-1c1bc7ef432b', 
         prod: '768298103' 
     },
     { 
         vimr: '7b715c70-2689-4241-a07e-450c8aebf27c', 
         prod: '768298103' 
     },
     { 
         vimr: '7b715c70-2689-4241-a07e-450c8aebf27c', 
         prod: '392799267' 
     }
   ]
I have tried to condense the information with the following map reduce function:
function (keys, values) {
  var result = {};
  for (var k in values){
      var data = values[k];
      
      if (!result[data.vimr]){
        result[data.vimr] = {}
      }
      
      result[data.vimr][data.prod] = true;
  }
    
    return result;
}
However I seem to just get a return value of undefined from the query. I'm struggling to understand where I'm going wrong, or even how I can debug this. Any advice would be much appreciated.
