How to pass parameters to a map() function of a JSMapReduce job

#1

When running a JSMapReduce job, how can I reference externally-scoped variables from within the map() function? The below fails when I try to reference start and end.

   function exportSomeData(start, end) {
      var map = function(batch, objs, job) {
        objs.each(function(asset) {
          var scores = RiskScore.fetch({ 
                limit: maxExportBatchSize, 
                filter: "parent.id=='" + rsh.id + "' && start>dateTime(" + start + ") && end<dateTime(" + end + ")", 
                order: "start", 
                offset: i * maxExportBatchSize
              }).objs;
        // snipped
        });
      }

      var spec = JSMapReduceSpec.make({
        targetType: OilGasWell,
        include: "id, riskScores",
        filter: "exists(riskScores)",
        limit: -1,
        batchSize: 1,
        map: map
      });

     JS.mapReduce(spec);
}
0 Likes

#2

Use the context field in the JSMapReduceSpec, here is an example:

0 Likes