[mongodb-user] Using v8, mapreduce objects have no .constructor so tojson() crashes

55 views
Skip to first unread message

AndyM

unread,
May 13, 2010, 4:47:21 AM5/13/10
to mongodb-user, d...@possumpalace.org
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.

Eliot Horowitz

unread,
May 14, 2010, 11:13:34 AM5/14/10
to mongod...@googlegroups.com, d...@possumpalace.org
Got the bug report and the problem should be fixed.
Tomorrow (5/15) nightly should have the fix.
Or you can build yourself.

dan90

unread,
May 19, 2010, 10:28:01 PM5/19/10
to mongodb-user
Eliot, to clarify that: Are *all* the nightly builds v8? Or should i
continue to build my own v8 versions if I want it?
If i do download a given build, is there a simple way to work out
whether it's v8 or spidermonkey other than going for a performance
trial ;) ?

Cheers,
Dan

On May 15, 1:13 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> Got the bug report and the problem should be fixed.
> Tomorrow (5/15)nightlyshould have the fix.
> Or you canbuildyourself.
>
>
>
>
>
> On Thu, May 13, 2010 at 4:47 AM, AndyM <admac...@gmail.com> wrote:
> > Hi,
>
> > I've been using aV8buildof 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 toV8, as my
> > Looks like it might be a a bug that only occurs inV8, 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 inV8-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 athttp://groups.google.com/group/mongodb-user?hl=en.
>
> --
> 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 athttp://groups.google.com/group/mongodb-user?hl=en.

Eliot Horowitz

unread,
May 19, 2010, 10:51:38 PM5/19/10
to mongod...@googlegroups.com

dan90

unread,
May 20, 2010, 10:17:03 PM5/20/10
to mongodb-user
Thanks!
in danger of getting OT here... but is there an OSX nightly v8 build
too?

We've been using Homebrew to get around the prerequisite pain on that
platform - http://github.com/mxcl/homebrew/ - but I like lazy, very
much.

--d()

On May 20, 12:51 pm, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> No - there is a special v8 build.http://downloads.mongodb.org/linux/mongodb-linux-x86_64-v8-latest.tgz

Eliot Horowitz

unread,
May 24, 2010, 10:50:30 AM5/24/10
to mongod...@googlegroups.com
No v8 osx build at the moment.

Benjamin Polidore

unread,
Aug 19, 2010, 5:57:14 PM8/19/10
to mongod...@googlegroups.com
is there a windows V8 build? 

Eliot Horowitz

unread,
Aug 20, 2010, 12:13:46 AM8/20/10
to mongod...@googlegroups.com
No - v8 isn't officially supported, still an experiment, so we only
release linux 64 bit builds.
Should be pretty easy to build yourself though.
Just add --usev8 to scons

Benjamin Polidore

unread,
Aug 20, 2010, 11:52:59 AM8/20/10
to mongod...@googlegroups.com
ok. cool. unfortunately, corporate mandate gives me windows servers.

do you have any performance statistics on aggregations or map reduce with V8? 

Eliot Horowitz

unread,
Aug 20, 2010, 11:55:19 AM8/20/10
to mongod...@googlegroups.com
We've seen mixed results - which is why we haven't switched at this point.
Reply all
Reply to author
Forward
0 new messages