0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/mr_bigobject.js
Eliot Horowitz c0fa671318 map/reduce no longer uses temp collections.
you have to specify out
SERVER-1837
2010-12-16 16:41:28 -05:00

42 lines
833 B
JavaScript

t = db.mr_bigobject
t.drop()
s = "";
while ( s.length < ( 1024 * 1024 ) ){
s += "asdasdasd";
}
for ( i=0; i<10; i++ )
t.insert( { _id : i , s : s } )
m = function(){
emit( 1 , this.s + this.s );
}
r = function( k , v ){
return 1;
}
assert.throws( function(){ t.mapReduce( m , r , "mr_bigobject_out" ); } , "emit should fail" )
m = function(){
emit( 1 , this.s );
}
assert.eq( { 1 : 1 } , t.mapReduce( m , r , "mr_bigobject_out" ).convertToSingleObject() , "A1" )
r = function( k , v ){
total = 0;
for ( var i=0; i<v.length; i++ ){
var x = v[i];
if ( typeof( x ) == "number" )
total += x
else
total += x.length;
}
return total;
}
assert.eq( { 1 : 10 * s.length } , t.mapReduce( m , r , "mr_bigobject_out" ).convertToSingleObject() , "A1" )