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

CodeWScope not working in reduce function for M/R

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.7.2
    • Affects Version/s: None
    • Component/s: JavaScript
    • None
    • Environment:
      Ruby 1.8 / Ruby 1.9

      With $where you can do something like:

      posts.find($where => Code.new("i < 3",

      {i: 2}

      ))

      and there will be scope created with i variable set to 2 fror "i < 3" part.

      However, this doesn't work with map-reduce functions.

      map = "function() { emit(this._id,

      {foo: 'bar'); }

      "
      reduce = Code.new(
      "function(key, values)

      { return x; }

      ",

      {x: 1}

      )
      posts.map_reduce(map, reduce)

      This throws an error like:
      map-reduce failed: assertion: invoke failed: JS Error: ReferenceError: x is not defined nofile_b:3

            Assignee:
            tonyh Tony Hannan
            Reporter:
            hubertlepicki Hubert Lepicki
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: