diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-03-30 03:23:37 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-04-28 08:50:23 -0400 |
commit | 4b5f2b33e8e7e858990bd4837f37c82290b7150d (patch) | |
tree | 9f6d1f4d3c02377e5176f1d05805b40f885a163b | |
parent | 19d7fd194d5793441b945ef07f1ae46b0de6ceaa (diff) | |
download | mongo-4b5f2b33e8e7e858990bd4837f37c82290b7150d.tar.gz |
fix m/r handling of undefined SERVER-2861
-rw-r--r-- | db/commands/mr.cpp | 13 | ||||
-rw-r--r-- | jstests/mr_undef.js | 22 |
2 files changed, 34 insertions, 1 deletions
diff --git a/db/commands/mr.cpp b/db/commands/mr.cpp index 16c604acfa6..b9f5b59821c 100644 --- a/db/commands/mr.cpp +++ b/db/commands/mr.cpp @@ -758,7 +758,18 @@ namespace mongo { BSONObj fast_emit( const BSONObj& args ) { uassert( 10077 , "fast_emit takes 2 args" , args.nFields() == 2 ); uassert( 13069 , "an emit can't be more than half max bson size" , args.objsize() < ( BSONObjMaxUserSize / 2 ) ); - (*_tl)->emit( args ); + + if ( args.firstElement().type() == Undefined ) { + BSONObjBuilder b( args.objsize() ); + b.appendNull( "" ); + BSONObjIterator i( args ); + i.next(); + b.append( i.next() ); + (*_tl)->emit( b.obj() ); + } + else { + (*_tl)->emit( args ); + } return BSONObj(); } diff --git a/jstests/mr_undef.js b/jstests/mr_undef.js new file mode 100644 index 00000000000..e162f99836b --- /dev/null +++ b/jstests/mr_undef.js @@ -0,0 +1,22 @@ + +t = db.mr_undef +t.drop() + +outname = "mr_undef_out" +out = db[outname] +out.drop() + +t.insert({x : 0}) + +var m = function() { emit(this.mod, this.x); } +var r = function(k,v) { total = 0; for(i in v) { total+= v[i]; } return total; } + +res = t.mapReduce(m, r, {out : outname } ) + +assert.eq( 0 , out.find( { _id : { $type : 6 } } ).itcount() , "A1" ) +assert.eq( 1 , out.find( { _id : { $type : 10 } } ).itcount() , "A2" ) + +x = out.findOne() +assert.eq( x , out.findOne( { _id : x["_id"] } ) , "A3" ) + + |