JS MapReduce job example


Following is an JS MapReduce job example that you can run without need for code provisioning .

Define what the job will do inside the map and reduce functions

var mapper = function (batch, objs, job) {
  // map logic goes here
var reducer = function (batch, objs, job) {
  // reduce logic goes here

Lunch the job

var spec = JSMapReduceSpec.make({
  targetType: MyType, // e.g. Facility
  include: ...,       // include any field from target type
  limit: ...,         // limit number of objects to be processed by the MapReduce job
  batchSize: ...,     // set the size of objects batch that will be passed to map()
  context: {
    // any context information useful for the map() and reduce()
  map: mapper.toString(),
  reduce: reducer.toString()
var job = JS.mapReduce(spec);

Check the status of the job

c3Grid(JSMapReduceJob.fetch({filter: Filter.eq('id', job.id)}))


@bachr can I pass more than one targetType ? For example if I want to pass three type: PointMeasurement, RegisterMeasurement, Measurement, is possible?


No you cannot because the job will run against the instance of only one type.