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

MapReduce: when using scope with a function closures are broken

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.1.0
    • Component/s: MapReduce
    • None
    • ALL
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      When using the "scope" option with a function that has formed a closure, the map function will break this closure and throw a ReferenceError when the supplied function is invoked.

      This may be done intentionally... the docs are a bit sparse with regards to the "scope" option.

      See the following:

      test.js
      > db.collection.save({})
      
      > fn = function(){ var x = 1; return function(){ return x; }}()
      function () {
          return x;
      }
      
      > fn()
      1
      
      > db.collection.mapReduce(function(){fn()}, function(){}, {out:'inline', scope:{fn:fn}})
      Fri Mar 23 12:52:59 uncaught exception: map reduce failed:{
      	"assertion" : "map invoke failed: JS Error: ReferenceError: x is not defined nofile_b:1",
      	"assertionCode" : 9014,
      	"errmsg" : "db assertion failure",
      	"ok" : 0
      }
      > 
      

            Assignee:
            schwerin@mongodb.com Andy Schwerin
            Reporter:
            mikeycgto Michael Coyne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: