[SERVER-520] CodeWScope not working in reduce function for M/R Created: 04/Jan/10  Updated: 12/Jul/16  Resolved: 08/Oct/10

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 1.7.2

Type: Bug Priority: Minor - P4
Reporter: Hubert Lepicki Assignee: Tony Hannan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ruby 1.8 / Ruby 1.9


Participants:

 Description   

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



 Comments   
Comment by Tony Hannan [ 08/Oct/10 ]

Map/reduce/finalize function scopes now get added to the general mapReduce scope.
Ideally, each would be a nested scope of the general mapReduce scope, but this was easier to implement given the current code.

Comment by auto [ 08/Oct/10 ]

Author:

{'login': 'TonyGen', 'name': 'Tony Hannan', 'email': 'tony@10gen.com'}

Message: SERVER-520: Map/reduce/finalize function can now include their own scope. They get merged with the m/r's general scope.
http://github.com/mongodb/mongo/commit/4accb330447e9443e2ec04af030abaa0c0f1a4c7

Comment by Eliot Horowitz (Inactive) [ 05/Jan/10 ]

in the meantime you can use the "scope" attribute" on the map/reduce command

Comment by Michael Dirolf [ 04/Jan/10 ]

Just assigning this to eliot as I assume it's not high priority enough to need a fix before you're back. Not sure if you want to fix yourself or assign to mathias.

Generated at Thu Feb 08 02:54:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.