summaryrefslogtreecommitdiff
path: root/jstests/sharding/large_skip_one_shard.js
blob: 49e6551dec0b3ed14d1784531b5516faa6d74b45 (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
/**
 * Tests that a sharded query targeted to a single shard will use passed-in skip.
 */
var st = new ShardingTest({ shards : 2, mongos : 1});

var mongos = st.s0;
var shards = mongos.getDB( "config" ).shards.find().toArray();

var admin = mongos.getDB( "admin" );
var collSharded = mongos.getCollection( "testdb.collSharded" );
var collUnSharded = mongos.getCollection( "testdb.collUnSharded" );

// Set up a sharded and unsharded collection
assert( admin.runCommand({ enableSharding : collSharded.getDB() + "" }).ok );
printjson( admin.runCommand({ movePrimary : collSharded.getDB() + "", to : shards[0]._id }) );
assert( admin.runCommand({ shardCollection : collSharded + "", key : { _id : 1 } }).ok );
assert( admin.runCommand({ split : collSharded + "", middle : { _id : 0 } }).ok );
assert( admin.runCommand({ moveChunk : collSharded + "",
                           find : { _id : 0 },
                           to : shards[1]._id }).ok );

function testSelectWithSkip(coll){

    for (var i = -100; i < 100; i++) {
        assert.writeOK(coll.insert({ _id : i }));
    }

    // Run a query which only requires 5 results from a single shard
    var explain = coll.find({ _id : { $gt : 1 }}).sort({ _id : 1 })
                                                 .skip(90)
                                                 .limit(5)
                                                 .explain("executionStats");

    assert.lt(explain.executionStats.nReturned, 90);
}

testSelectWithSkip(collSharded);
testSelectWithSkip(collUnSharded);

jsTest.log("DONE!");
st.stop();