Hi,
I've been using a V8 build of mongo (v1.4.2, 32bit, OS X), and I've
run into an issue where if you call tojson() on "this" within the map
function of a mapreduce query, the call fails within tojsonObject, as
it can't find the .tojson property of the .constructor property of the
particular object. I believe this issue is peculiar to V8, as my
colleague couldn't reproduce it on a similar setup using the standard
build.
A test case that illustrates this is below:
> 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
}
// fails - no mapreduce output for me.
The only difference between the two is the print(tojson(this));
Looks like it might be a a bug that only occurs in V8, although maybe
I'm doing something else strange here (apart froma slightly pointless
mapreduce of course).
In any case, it seems likely that check for null in the tojsonObject()
function of that .constructor attribute would make it more robust, but
I wonder if there's also something else sinister going on in V8-land
that's causing the null-valued .constructor (or if it's something that
doesn't matter).
Anyway, let me know if I should posting a bug report about this.
Thanks,
Andy
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to
mongod...@googlegroups.com.
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mongodb-user?hl=en.