Permalink
Browse files

fix m/r handling of undefined SERVER-2861

  • Loading branch information...
1 parent fb9ed29 commit 8cd20b51fd4defa44343decb235a5053d66381d6 @erh erh committed Mar 30, 2011
Showing with 34 additions and 1 deletion.
  1. +12 −1 db/commands/mr.cpp
  2. +22 −0 jstests/mr_undef.js
View
@@ -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();
}
View
@@ -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" )
+
+

0 comments on commit 8cd20b5

Please sign in to comment.