Mongo Command Exception on processing more than 100 record

Hi Team,

Mongo DB version - 4.2.13
Mongo java Driver Version - 3.12.0

I am running mapReduce on my collection , it runs fine until we have =< 100 records. As soon as the record exceeds 100 following error is thrown.

com.mongodb.MongoCommandException: Command failed with error 139 (JSInterpreterFailure): 'TypeError: reducedObject is undefined :

PFA my map and reduce code -
function(){
var key = this.createdDate.getFullYear();
var value = {
totalOrderPrice : this.totalOrderPrice,
totalOrderValue :this.totalOrderValue,
instrumentType : this.instrumentType,
createdDate : this.createdDate,
data : {
status : “ok”,
name : “OverallSummary”,
metadata : [{
type : “transaction”,
size : 5
},{
type : “inventory”,
size : 3
}],
summaries : ,
charts :
}
};
emit(key,value);
}

function(key, values){
var reducedObject = values[0].data ;
reducedObject.status = “success”;
var poSum = 0, soSum = 0, poCount = 0, soCount = 0, act = 0, exp = 0, per = 0;
var date = null;
var todayDate = new Date();
//var granSummary = this.granSummary;
//var granChart = this.granChart;
var perDaySale = 0;
var availMap = this.availMap;

for(var i = 0; i<values.length ; i++){
date = values[i].createdDate;
if((date.getDate() == todayDate.getDate())
&& (date.getMonth() == todayDate.getMonth())
&& (date.getFullYear() == todayDate.getFullYear())){
if(values[i].instrumentType == “PO”){
if(values[i].totalOrderPrice != undefined){
poSum += values[i].totalOrderPrice;
poCount ++;
}
}

       if(values[i].instrumentType == "SO"){
          if(values[i].totalOrderPrice != undefined){
              soSum += values[i].totalOrderPrice;
              soCount ++;
          }
      }
  }

  if(values[i].instrumentType == "PO"){
      if(values[i].totalOrderPrice != undefined)
          exp += values[i].totalOrderPrice;
  }

}

if(act > 0 && exp > 0){
per = (act.toFixed(2)/exp.toFixed(2)) * 100;
}

reducedObject.summaries.push({name: “order”, type: “transaction”, sum : poSum, count : poCount});

reducedObject.charts.push({name: “Primary Filtrate”, type: “transaction”, expected : exp.toFixed(2), actual : act.toFixed(2), percentage : per});

reducedObject.charts.push({name: “1 DAY”, type: “inventory”, percentage : availMap[“1day”]});
reducedObject.charts.push({name: “5 DAYS”, type: “inventory”, percentage : availMap[“5days”]});
reducedObject.charts.push({name: “PER UNIT”, type: “inventory”, percentage : availMap[“1unit”]});

reducedObject.metadata.push({granularity : {keys : [“expected”, “actual”],measuringUnit : “Hour”}});
reducedObject.metadata.push({displayRule : {ruleType : “Threshold”,indicator : “Color”,keys : [“percentage”],constraints : [{from : 0, to : 40,values : [“Red”]},{from : 40,to : 70,values : [“Yellow”]},{from : 70,to : 100,values : [“Green”]}]}});

return reducedObject;
}