Skip to content

Commit

Permalink
SERVER-446 js implementation of keySet()
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Dec 21, 2009
1 parent 83d4e4f commit 81b7e05
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 446 deletions.
2 changes: 1 addition & 1 deletion jstests/fm2.js
Expand Up @@ -5,5 +5,5 @@ t.drop();
t.insert( { "one" : { "two" : {"three":"four"} } } );

x = t.find({},{"one.two":1})[0]
assert.eq( 1 , x.one.keySet().length , "ks l 1" );
assert.eq( 1 , Object.keySet( x.one ).length , "ks l 1" );

4 changes: 2 additions & 2 deletions jstests/jni4.js
Expand Up @@ -16,7 +16,7 @@ assert.eq( "/abc/i" , real.c.toString() , "regex 1" );
var cursor = t.find( { $where :
function(){
fullObject;
assert.eq( 7 , obj.keySet().length , "A" )
assert.eq( 7 , Object.keySet( obj ).length , "A" )
assert.eq( 1 , obj.a , "B" );
assert.eq( "abc" , obj.b , "C" );
assert.eq( "/abc/i" , obj.c.toString() , "D" );
Expand All @@ -37,7 +37,7 @@ t.save( { a : 2 , b : { c : 7 , d : "d is good" } } );
var cursor = t.find( { $where :
function(){
fullObject;
assert.eq( 3 , obj.keySet().length )
assert.eq( 3 , Object.keySet( obj ).length )
assert.eq( 2 , obj.a );
assert.eq( 7 , obj.b.c );
assert.eq( "d is good" , obj.b.d );
Expand Down
2 changes: 1 addition & 1 deletion jstests/mr1.js
Expand Up @@ -60,7 +60,7 @@ x.find().forEach( d );
z = {};
x.find().forEach( function(a){ z[a[ks]] = a.value.count; } );
d( z );
assert.eq( 3 , z.keySet().length , "C" );
assert.eq( 3 , Object.keySet( z ).length , "C" );
assert.eq( 2 , z.a , "D" );
assert.eq( 3 , z.b , "E" );
assert.eq( 3 , z.c , "F" );
Expand Down
4 changes: 2 additions & 2 deletions jstests/mr3.js
Expand Up @@ -28,7 +28,7 @@ r = function( key , values ){
res = t.mapReduce( m , r );
z = res.convertToSingleObject()

assert.eq( 3 , z.keySet().length , "A1" );
assert.eq( 3 , Object.keySet( z ).length , "A1" );
assert.eq( 2 , z.a.count , "A2" );
assert.eq( 3 , z.b.count , "A3" );
assert.eq( 3 , z.c.count , "A4" );
Expand All @@ -38,7 +38,7 @@ res.drop();
res = t.mapReduce( m , r , { mapparams : [ 2 , 2 ] } );
z = res.convertToSingleObject()

assert.eq( 3 , z.keySet().length , "B1" );
assert.eq( 3 , Object.keySet( z ).length , "B1" );
assert.eq( 8 , z.a.count , "B2" );
assert.eq( 12 , z.b.count , "B3" );
assert.eq( 12 , z.c.count , "B4" );
Expand Down
4 changes: 2 additions & 2 deletions jstests/mr4.js
Expand Up @@ -26,7 +26,7 @@ r = function( key , values ){
res = t.mapReduce( m , r , { scope : { xx : 1 } } );
z = res.convertToSingleObject()

assert.eq( 3 , z.keySet().length , "A1" );
assert.eq( 3 , Object.keySet( z ).length , "A1" );
assert.eq( 2 , z.a.count , "A2" );
assert.eq( 3 , z.b.count , "A3" );
assert.eq( 3 , z.c.count , "A4" );
Expand All @@ -37,7 +37,7 @@ res.drop();
res = t.mapReduce( m , r , { scope : { xx : 2 } } );
z = res.convertToSingleObject()

assert.eq( 3 , z.keySet().length , "A1" );
assert.eq( 3 , Object.keySet( z ).length , "A1" );
assert.eq( 4 , z.a.count , "A2" );
assert.eq( 6 , z.b.count , "A3" );
assert.eq( 6 , z.c.count , "A4" );
Expand Down
2 changes: 1 addition & 1 deletion jstests/mr5.js
Expand Up @@ -29,7 +29,7 @@ res = t.mapReduce( m , r , { scope : { xx : 1 } } );
res.find().forEach( printjson )

z = res.convertToSingleObject()
assert.eq( 2 , z.keySet().length , "A" )
assert.eq( 2 , Object.keySet( z ).length , "A" )
assert.eq( [ 9 , 11 , 30 ] , z["1"].stats , "B" )
assert.eq( [ 9 , 41 , 41 ] , z["2"].stats , "B" )

Expand Down
10 changes: 5 additions & 5 deletions jstests/set1.js
Expand Up @@ -5,12 +5,12 @@ t.drop();
t.insert( { _id : 1, emb : {} });

t.update( { _id : 1 }, { $set : { emb : { 'a.dot' : 'data'} }});
assert.eq( 1 , t.findOne().emb.keySet().length , "A" );
assert.eq( "a.dot" , t.findOne().emb.keySet()[0] , "B" );
assert.eq( 1 , Object.keySet( t.findOne().emb ).length , "A" );
assert.eq( "a.dot" , Object.keySet( t.findOne().emb )[0] , "B" );

t.update( { _id : 1 }, { $set : { 'emb.b' : { dot : 'data'} }});
assert.eq( 2 , t.findOne().emb.keySet().length , "C" );
//assert.eq( "a.dot" , t.findOne().emb.keySet()[0] , "D" );
//assert.eq( "b" , t.findOne().emb.keySet()[0] , "E" );
assert.eq( 2 , Object.keySet( t.findOne().emb ).length , "C" );
//assert.eq( "a.dot" , Object.keySet( t.findOne().emb )[0] , "D" );
//assert.eq( "b" , Obkect.keySet( t.findOne().emb )[0] , "E" );


2 changes: 1 addition & 1 deletion jstests/sharding/features2.js
Expand Up @@ -95,7 +95,7 @@ doMR = function( n ){

var z = {};
x.find().forEach( function(a){ z[a._id] = a.value.count; } );
assert.eq( 3 , z.keySet().length , "MR T2 " + n );
assert.eq( 3 , Object.keySet( z ).length , "MR T2 " + n );
assert.eq( 2 , z.a , "MR T2 " + n );
assert.eq( 3 , z.b , "MR T2 " + n );
assert.eq( 3 , z.c , "MR T2 " + n );
Expand Down
12 changes: 6 additions & 6 deletions jstests/update6.js
Expand Up @@ -6,11 +6,11 @@ t.save( { a : 1 , b : { c : 1 , d : 1 } } );

t.update( { a : 1 } , { $inc : { "b.c" : 1 } } );
assert.eq( 2 , t.findOne().b.c , "A" );
assert.eq( "c,d" , t.findOne().b.keySet().toString() , "B" );
assert.eq( "c,d" , Object.keySet( t.findOne().b ).toString() , "B" );

t.update( { a : 1 } , { $inc : { "b.0e" : 1 } } );
assert.eq( 1 , t.findOne().b["0e"] , "C" );
assert.eq( "0e,c,d" , t.findOne().b.keySet().toString() , "D" );
assert.eq( "0e,c,d" , Object.keySet( t.findOne().b ).toString() , "D" );

// -----

Expand All @@ -23,9 +23,9 @@ t.save( {"_id" : 2 ,
);


assert.eq( 4 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 1 : ks before" );
assert.eq( 4 , Object.keySet( t.find({_id:2},{b3:1})[0].b3 ).length , "test 1 : ks before" );
t.update({_id:2},{$inc: { 'b3.0719' : 1}},true)
assert.eq( 5 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 1 : ks after" );
assert.eq( 5 , Object.keySet( t.find({_id:2},{b3:1})[0].b3 ).length , "test 1 : ks after" );


// -----
Expand All @@ -39,8 +39,8 @@ t.save( {"_id" : 2 ,
);


assert.eq( 4 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 2 : ks before" );
assert.eq( 4 , Object.keySet( t.find({_id:2},{b3:1})[0].b3 ).length , "test 2 : ks before" );
printjson( t.find({_id:2},{b3:1})[0].b3 )
t.update({_id:2},{$inc: { 'b3.0719' : 1}} )
printjson( t.find({_id:2},{b3:1})[0].b3 )
assert.eq( 5 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 2 : ks after" );
assert.eq( 5 , Object.keySet( t.find({_id:2},{b3:1})[0].b3 ).length , "test 2 : ks after" );

0 comments on commit 81b7e05

Please sign in to comment.