summaryrefslogtreecommitdiff
path: root/jstests/sharding/shard_collection_verify_initial_chunks.js
blob: 0538bed1b3479d0d15a42f40d215be490e21c77f (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
//
// Verify numInitialChunks can not be set for non hashed key or nonempty collections
//

(function() {
    'use strict';

    var st = new ShardingTest({mongos: 1, shards: 2});
    var kDbName = 'db';
    var mongos = st.s0;

    assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));

    assert.commandFailed(mongos.adminCommand(
        {shardCollection: kDbName + '.foo', key: {aKey: 1}, numInitialChunks: 5}));

    assert.writeOK(mongos.getDB(kDbName).foo.insert({aKey: 1}));
    assert.commandWorked(mongos.getDB(kDbName).foo.createIndex({aKey: "hashed"}));
    assert.commandFailed(mongos.adminCommand(
        {shardCollection: kDbName + '.foo', key: {aKey: "hashed"}, numInitialChunks: 5}));

    assert.writeOK(mongos.getDB(kDbName).foo.remove({}));
    assert.commandWorked(mongos.adminCommand(
        {shardCollection: kDbName + '.foo', key: {aKey: "hashed"}, numInitialChunks: 5}));

    mongos.getDB(kDbName).dropDatabase();

    st.stop();

})();