[SERVER-637] Scoped variables in MongoCode do not work in map reduce operations (ReferenceError) Created: 15/Feb/10  Updated: 15/Feb/10  Resolved: 15/Feb/10

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

Type: Bug Priority: Major - P3
Reporter: Mike Dransfield Assignee: Eliot Horowitz (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

The following code should not give an error.

<?php
$m = new Mongo();
$db = $m->selectDB('example');
$c = $db->selectCollection('example');
$c->save(array('test'=>'foo'));
$ordered_options['mapreduce'] = 'example';
$map_str = 'function(){for (var i=0;i<testvar.length;i++){emit(i,
testvar[i]);}}';
$map_code = new MongoCode($map_str, array('testvar' => array('a', 'b',
'c')));
$reduce_code = new MongoCode('function(key, values)

{return 1;}

');
$options = array(
'mapreduce' => 'example',
'map' => $map_code,
'reduce' => $reduce_code
);
$mr_res = $db->command($options);
print_r($map_code);
print_r($mr_res);
?>
OUTPUT
MongoCode Object
(
[code] => function(){for (var i=0;i<testvar.length;i++){emit(i,
testvar[i]);}}
[scope] => Array
(
[testvar] => Array
(
[0] => a
[1] => b
[2] => c
)
)
)
Array
(
[errmsg] => assertion: map invoke failed: JS Error:
ReferenceError: testvar is not defined nofile_b:0
[ok] => 0
)



 Comments   
Comment by Eliot Horowitz (Inactive) [ 15/Feb/10 ]

See SERVER-520
Though i'm not sure this really makes sense.
See: "scope" on http://www.mongodb.org/display/DOCS/MapReduce for a better more general method.

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