summaryrefslogtreecommitdiff
path: root/jstests/core/sortc.js
blob: f9aa202508b3a57a1091ab8a2b536af5ff52e31a (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
// Test sorting with skipping and multiple candidate query plans.

t = db.jstests_sortc;
t.drop();

t.save( {a:1} );
t.save( {a:2} );

function checkA( a, sort, skip, query ) {
    query = query || {};
    assert.eq( a, t.find( query ).sort( sort ).skip( skip )[ 0 ].a );
}

function checkSortAndSkip() {
    checkA( 1, {a:1}, 0 );
    checkA( 2, {a:1}, 1 );

    checkA( 1, {a:1}, 0, {a:{$gt:0},b:null} );
    checkA( 2, {a:1}, 1, {a:{$gt:0},b:null} );

    checkA( 2, {a:-1}, 0 );
    checkA( 1, {a:-1}, 1 );

    checkA( 2, {a:-1}, 0, {a:{$gt:0},b:null} );
    checkA( 1, {a:-1}, 1, {a:{$gt:0},b:null} );

    checkA( 1, {$natural:1}, 0 );
    checkA( 2, {$natural:1}, 1 );

    checkA( 2, {$natural:-1}, 0 );
    checkA( 1, {$natural:-1}, 1 );
}

checkSortAndSkip();

t.ensureIndex( {a:1} );
checkSortAndSkip();