File: hash_shard_non_empty.js

package info (click to toggle)
mongodb 1%3A3.2.11-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 196,404 kB
  • sloc: cpp: 1,412,793; ansic: 504,961; python: 78,522; perl: 5,837; sh: 5,661; java: 4,202; makefile: 1,784; pascal: 617; xml: 176; asm: 128
file content (22 lines) | stat: -rw-r--r-- 743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Hash sharding on a non empty collection should not pre-split.

var s = new ShardingTest({name: jsTestName(), shards: 3, mongos: 1, verbose: 1});
var dbname = "test";
var coll = "foo";
var db = s.getDB(dbname);
db.adminCommand({enablesharding: dbname});
s.ensurePrimaryShard('test', 'shard0001');

// for simplicity turn off balancer
s.stopBalancer();

db.getCollection(coll).insert({a: 1});

db.getCollection(coll).ensureIndex({a: "hashed"});
var res = db.adminCommand({shardcollection: dbname + "." + coll, key: {a: "hashed"}});
assert.eq(res.ok, 1, "shardcollection didn't work");
db.printShardingStatus();
var numChunks = s.config.chunks.count();
assert.eq(numChunks, 1, "sharding non-empty collection should not pre-split");

s.stop();