-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.4.2
-
Component/s: None
-
None
-
Environment:OS X, with v8 build
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)
;
> mapTest = function()
> var res = db.runCommand(
{mapreduce: 'test_coll', map: mapTest, reduce: reduceTest, out: 'test_mr_out1', verbose: true});
> res
,
"ok" : 1
}
// works fine without tojson() call
> mapTestFail = function()
{ ... print("in mapTest"); ... print(tojson(this)); ... emit('blah', 1); ... };
> var res = db.runCommand(
);
> 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.