~ubuntu-branches/ubuntu/trusty/mongodb/trusty-proposed

« back to all changes in this revision

Viewing changes to jstests/sort1.js

  • Committer: Bazaar Package Importer
  • Author(s): Antonin Kral
  • Date: 2010-01-29 19:48:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100129194845-8wbmkf626fwcavc9
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// test sorting, mainly a test ver simple with no index
 
2
 
 
3
debug = function( s ){
 
4
    //print( s );
 
5
}
 
6
 
 
7
t = db.sorrrt;
 
8
t.drop();
 
9
 
 
10
t.save({x:3,z:33});
 
11
t.save({x:5,z:33});
 
12
t.save({x:2,z:33});
 
13
t.save({x:3,z:33});
 
14
t.save({x:1,z:33});
 
15
 
 
16
debug( "a" )
 
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 );
 
24
    t.ensureIndex({x:1});
 
25
 
 
26
}
 
27
 
 
28
debug( "b" )
 
29
assert(t.validate().valid);
 
30
 
 
31
 
 
32
db.sorrrt2.drop();
 
33
db.sorrrt2.save({x:'a'});
 
34
db.sorrrt2.save({x:'aba'});
 
35
db.sorrrt2.save({x:'zed'});
 
36
db.sorrrt2.save({x:'foo'});
 
37
 
 
38
debug( "c" )
 
39
 
 
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" );
 
46
}
 
47
 
 
48
debug( "d" )
 
49
 
 
50
assert(db.sorrrt2.validate().valid);