[SERVER-1119] Under v8, objects in map() have null value for .constructor Created: 14/May/10  Updated: 14/May/10  Resolved: 14/May/10

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

Type: Bug Priority: Major - P3
Reporter: Andy MacKinlay Assignee: Eliot Horowitz (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS X, with v8 build


Participants:

 Description   

From my forum post at:
http://groups.google.com/group/mongodb-user/browse_thread/thread/2e99cf6df485f0f5#

Under V8, the 'this' object in the map function of a mapreduce call has a null value for .constructor. I'm not sure if this if malformed JS, or by design, but if it is by design, then it would be nice if tojson() could handle such objects (issue 1118)

Reproducing the test case from the forum post:

> rec =

{foo: 'bar'} { "foo" : "bar" }

> db.test_coll.save(rec)
> reduceTest = function(key, valueArray)

{ ... print("in reduceTest"); ... return 2; ... }

;
> mapTest = function()

{ ... print("in mapTest"); ... emit('blah', 1); ... }

> var res = db.runCommand(

{mapreduce: 'test_coll', map: mapTest, reduce: reduceTest, out: 'test_mr_out1', verbose: true}

);
> res

{ "result" : "test_mr_out1", //... etc ... }

,
"ok" : 1
}

// works fine without tojson() call

> mapTestFail = function()

{ ... print("in mapTest"); ... print(tojson(this)); ... emit('blah', 1); ... }

;
> var res = db.runCommand(

{mapreduce: 'test_coll', map: mapTestFail, reduce: reduceTest, out: 'test_mr_out1', verbose: true}

);
> res

{
"errmsg" : "assertion: map invoke failed: error in invoke:
localConnect 1:397 TypeError: Cannot read property 'tojson' of null
if ( typeof( x.constructor.tojson ) == \"function\" &&
x.constructor.tojson != t
^
",
"ok" : 0
}

It's likely that something out of this and 1118 is invalid, but I feel that at least one of them is probably a valid issue.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 14/May/10 ]

This is fine - fixed SERVER--1118

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