Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8632

System.js functions are not available to map/reduce jobs

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.0-rc2
    • Affects Version/s: 2.4.0-rc0
    • Component/s: MapReduce
    • None
    • Environment:
      OSX
    • ALL
    • Hide

      In 2.4.0-rc0:

      > db.system.js.save({_id: "sum", value: function (x, y) { return x + y; }});
      > db.records.insert(

      {foo:'bar'}

      )
      > db.records.mapReduce(function()

      { sum(1,2) },function() {}, {out: 'test_mr_out'});
      Wed Feb 20 10:21:53.844 map reduce failed:{
      "errmsg" : "exception: map invoke failed: ReferenceError: sum is not defined _funcs1:1",
      "code" : 9014,
      "ok" : 0
      } src/mongo/shell/collection.js:939

      In 2.2.0:

      > db.system.js.save({_id: "sum", value: function (x, y) { return x + y; }});
      > db.records.insert({foo:'bar'})
      > db.records.mapReduce(function() { sum(1,2) }

      ,function() {},

      {out: 'test_mr_out'}

      );
      {
      "result" : "test_mr_out",
      "timeMillis" : 59,
      "counts" :

      { "input" : 36, "emit" : 0, "reduce" : 0, "output" : 0 }

      ,
      "ok" : 1,
      }

      Show
      In 2.4.0-rc0: > db.system.js.save({_id: "sum", value: function (x, y) { return x + y; }}); > db.records.insert( {foo:'bar'} ) > db.records.mapReduce(function() { sum(1,2) },function() {}, {out: 'test_mr_out'}); Wed Feb 20 10:21:53.844 map reduce failed:{ "errmsg" : "exception: map invoke failed: ReferenceError: sum is not defined _funcs1:1", "code" : 9014, "ok" : 0 } src/mongo/shell/collection.js:939 In 2.2.0: > db.system.js.save({_id: "sum", value: function (x, y) { return x + y; }}); > db.records.insert({foo:'bar'}) > db.records.mapReduce(function() { sum(1,2) } ,function() {}, {out: 'test_mr_out'} ); { "result" : "test_mr_out", "timeMillis" : 59, "counts" : { "input" : 36, "emit" : 0, "reduce" : 0, "output" : 0 } , "ok" : 1, }

      It does not appear that functions defined in system.js are available to map reduce jobs in 2.4.0-rc0. In 2.2.0 and before these functions were available. Without the ability to add functions to system.js for map reduce jobs, jobs with common functionality or that rely on JS libraries become unmanageable. Also, the full jobs must be sent to the server rather than simply calling a function defined in system.js

            Assignee:
            benjamin.becker Ben Becker
            Reporter:
            aquina Andre Quina
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: