[SERVER-5416] js increment operators (ob.prop += ob2.prop) do not work, after assigment like this ob = ob2.pop() Created: 27/Mar/12  Updated: 30/Mar/12  Resolved: 30/Mar/12

Status: Closed
Project: Core Server
Component/s: JavaScript, MapReduce
Affects Version/s: 2.1.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Azat Khuzhin Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

r2.1.0-1580-g0c1a6bd (v8)
v8 engine: Version 3.9.23


Operating System: ALL
Participants:

 Description   

/**
 * 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);



 Comments   
Comment by Eliot Horowitz (Inactive) [ 30/Mar/12 ]

SERVER-5379

Generated at Thu Feb 08 03:08:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.