-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
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)
');
$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
)