summaryrefslogtreecommitdiff
path: root/jstests/sort4.js
blob: 5174b46f41f37cceb3d295cc86e115f99d663d60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
t = db.sort4;
t.drop();


function nice( sort , correct , extra ){
    var c = t.find().sort( sort );
    var s = "";
    c.forEach( 
        function(z){
            if ( s.length )
                s += ",";
            s += z.name;
            if ( z.prename )
                s += z.prename;
        }
    );
    print( tojson( sort ) + "\t" + s );
    if ( correct )
        assert.eq( correct , s , tojson( sort ) + "(" + extra + ")" );
    return s;
}

t.save({name: 'A', prename: 'B'})
t.save({name: 'A', prename: 'C'})
t.save({name: 'B', prename: 'B'})
t.save({name: 'B', prename: 'D'})

nice( { name:1 } , "AB,AC,BB,BD" , "s1" );
nice( { prename : 1 } , "AB,BB,AC,BD" , "s2" );
nice( {name:1, prename:1} , "AB,AC,BB,BD" , "s3" );

t.save({name: 'A'})     
nice( {name:1, prename:1} , "A,AB,AC,BB,BD" , "e1" );          

t.save({name: 'C'})               
nice( {name:1, prename:1} , "A,AB,AC,BB,BD,C" , "e2" ); // SERVER-282

t.ensureIndex( { name : 1 , prename : 1 } );
nice( {name:1, prename:1} , "A,AB,AC,BB,BD,C" , "e2ia" ); // SERVER-282

t.dropIndexes();
t.ensureIndex( { name : 1  } );
nice( {name:1, prename:1} , "A,AB,AC,BB,BD,C" , "e2ib" ); // SERVER-282