diff options
Diffstat (limited to 'jstests/mr_outreduce.js')
-rw-r--r-- | jstests/mr_outreduce.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/jstests/mr_outreduce.js b/jstests/mr_outreduce.js new file mode 100644 index 00000000000..e5878366fe4 --- /dev/null +++ b/jstests/mr_outreduce.js @@ -0,0 +1,41 @@ + +t = db.mr_outreduce; +t.drop(); + +t.insert( { _id : 1 , a : [ 1 , 2 ] } ) +t.insert( { _id : 2 , a : [ 2 , 3 ] } ) +t.insert( { _id : 3 , a : [ 3 , 4 ] } ) + +outName = "mr_outreduce_out"; +out = db[outName]; +out.drop(); + +m = function(){ for (i=0; i<this.a.length; i++ ) emit( this.a[i] , 1 ); } +r = function(k,vs){ return Array.sum( vs ); } + +function tos( o ){ + var s = ""; + for ( var i=0; i<100; i++ ){ + if ( o[i] ) + s += i + "_" + o[i] + "|" + } + return s; +} + + +res = t.mapReduce( m , r , { out : outName } ) + + +expected = { "1" : 1 , "2" : 2 , "3" : 2 , "4" : 1 } +assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "A" ); + +t.insert( { _id : 4 , a : [ 4 , 5 ] } ) +out.insert( { _id : 10 , value : "5" } ) // this is a sentinal to make sure it wasn't killed +res = t.mapReduce( m , r , { out : outName , outType : "reduce" , query : { _id : { $gt : 3 } } } ) + +expected["4"]++; +expected["5"] = 1 +expected["10"] = 5 +assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "B" ); + + |