[SERVER-5417] js add property do not work at emit() Created: 27/Mar/12  Updated: 15/Aug/12  Resolved: 30/Apr/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: Antoine Girbal
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Affected versions r2.1.0-1580-g0c1a6bd (v8), v8 engine: Version 3.9.23
Not affected versions 2.0.3-1 (spider monkey)


Issue Links:
Duplicate
duplicates SERVER-5379 js increment operators (ob.prop += ob... Closed
Operating System: ALL
Participants:

 Description   

/**
 * js add property do not work at emit()
 *
 * @link https://jira.mongodb.org/browse/
 *
 * 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: {bar: 1}});
testColl.insert({key: 1, foo: {bar: 1}});
testColl.insert({key: 1, foo: {bar: 1}});
 
res = db.runCommand({
	mapreduce: testCollName,
	map: function() {
		this.foo.additional = 1;
		assert(this.foo.additional, "additional not exist");
		emit(this.key, {foo: this.foo});
	},
	reduce: function(k, vals) {
		return 0;
	},
	out: {inline: 1}, // the same with "replace" and others
});
printjson(res);
 
testColl.drop();
 



 Comments   
Comment by Antoine Girbal [ 30/Apr/12 ]

this is same cause, src objects being read-only during MR processing.

Comment by Azat Khuzhin [ 27/Mar/12 ]

The same with delete

/**
 * js delete property do not work at emit()
 *
 * @link https://jira.mongodb.org/browse/SERVER-5417
 *
 * 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: {bar: 1}});
testColl.insert({key: 1, foo: {bar: 1}});
testColl.insert({key: 1, foo: {bar: 1}});
 
res = db.runCommand({
	mapreduce: testCollName,
	map: function() {
		delete this.foo.bar;
		assert(!this.foo.bar, "foo.bar exist");
		emit(this.key, 1);
	},
	reduce: function(k, vals) {
		return 0;
	},
	out: {inline: 1}, // the same with "replace" and others
});
printjson(res);
 
testColl.drop();
 

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