-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.1.0
-
Component/s: JavaScript, MapReduce
-
None
-
Environment:r2.1.0-1580-g0c1a6bd (v8)
v8 engine: Version 3.9.23
-
ALL
/** * js increment operators (ob.prop += ob2.prop) do not work, after assigment like this ob = ob2.pop() * * @link https://jira.mongodb.org/browse/@TODO * * Affected versions: r2.1.0-1580-g0c1a6bd (v8) * v8 engine: Version 3.9.23 * * Not affected versions: 2.0.3-1 (spider monkey) */ var testCollName = 'such-collection-can-t-exist'; var testColl = db.getCollection(testCollName); testColl.insert({key: 1, foo: 1}); testColl.insert({key: 1, foo: 1}); testColl.insert({key: 1, foo: 1}); res = db.runCommand({ mapreduce: testCollName, map: function() { emit(this.key, {foo: this.foo}); }, reduce: function(k, vals) { var result = vals.pop(); for (i in vals) { result.foo += vals[i].foo; assert(result.foo > 1, " must be :: > 1"); } return result; }, out: {inline: 1}, // the same with "replace" and others }); printjson(res); testColl.drop();
But this code works fine:
var arrayOfObjects = []; arrayOfObjects.push({key: 1, foo: 1}); arrayOfObjects.push({key: 1, foo: 1}); arrayOfObjects.push({key: 1, foo: 1}); object = arrayOfObjects.pop(); for (i in arrayOfObjects) { object.foo += arrayOfObjects[i].foo; } assert(object.foo > 1);
And this one too, works right
db.eval(function() { var arrayOfObjects = []; arrayOfObjects.push({key: 1, foo: 1}); arrayOfObjects.push({key: 1, foo: 1}); arrayOfObjects.push({key: 1, foo: 1}); object = arrayOfObjects.pop(); for (i in arrayOfObjects) { object.foo += arrayOfObjects[i].foo; } assert(object.foo > 1);