File: index_diag.js

package info (click to toggle)
mongodb 1%3A2.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,204 kB
  • sloc: cpp: 109,783; ansic: 101,073; python: 2,287; perl: 395; makefile: 370; sh: 242; asm: 46
file content (38 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download | duplicates (2)
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

t = db.index_diag
t.drop();

t.ensureIndex( { x : 1 } );

all = []
ids = []
xs = []

function r( a ){
    var n = []
    for ( var x=a.length-1; x>=0; x-- )
        n.push( a[x] );
    return n;
}

for ( i=1; i<4; i++ ){
    o = { _id : i , x : -i }
    t.insert( o );
    all.push( o );
    ids.push( { _id : i } );
    xs.push( { x : -i } );
}

assert.eq( all , t.find().sort( { _id : 1 } ).toArray() , "A1" );
assert.eq( r( all ) , t.find().sort( { _id : -1 } ).toArray() , "A2" );

assert.eq( all , t.find().sort( { x : -1 } ).toArray() , "A3" );
assert.eq( r( all ) , t.find().sort( { x : 1 } ).toArray() , "A4" );

assert.eq( ids , t.find().sort( { _id : 1 } )._addSpecial( "$returnKey" , true ).toArray() , "B1" )
assert.eq( r( ids ) , t.find().sort( { _id : -1 } )._addSpecial( "$returnKey" , true ).toArray() , "B2" )
assert.eq( xs , t.find().sort( { x : -1 } )._addSpecial( "$returnKey" , true ).toArray() , "B3" )
assert.eq( r( xs ) , t.find().sort( {x : 1 } )._addSpecial( "$returnKey" , true ).toArray() , "B4" )

assert.eq( r( xs ) , t.find().hint( { x : 1 } )._addSpecial( "$returnKey" , true ).toArray() , "B4" )