1
// test sorting, mainly a test ver simple with no index
17
for( var pass = 0; pass < 2; pass++ ) {
18
assert( t.find().sort({x:1})[0].x == 1 );
19
assert( t.find().sort({x:1}).skip(1)[0].x == 2 );
20
assert( t.find().sort({x:-1})[0].x == 5 );
21
assert( t.find().sort({x:-1})[1].x == 3 );
22
assert.eq( t.find().sort({x:-1}).skip(0)[0].x , 5 );
23
assert.eq( t.find().sort({x:-1}).skip(1)[0].x , 3 );
29
assert(t.validate().valid);
33
db.sorrrt2.save({x:'a'});
34
db.sorrrt2.save({x:'aba'});
35
db.sorrrt2.save({x:'zed'});
36
db.sorrrt2.save({x:'foo'});
40
for( var pass = 0; pass < 2; pass++ ) {
41
debug( tojson( db.sorrrt2.find().sort( { "x" : 1 } ).limit(1).next() ) );
42
assert.eq( "a" , db.sorrrt2.find().sort({'x': 1}).limit(1).next().x , "c.1" );
43
assert.eq( "a" , db.sorrrt2.find().sort({'x': 1}).next().x , "c.2" );
44
assert.eq( "zed" , db.sorrrt2.find().sort({'x': -1}).limit(1).next().x , "c.3" );
45
assert.eq( "zed" , db.sorrrt2.find().sort({'x': -1}).next().x , "c.4" );
50
assert(db.sorrrt2.validate().valid);