const dbName = "test";
|
const collName = "foo";
|
const ns = dbName + "." + collName;
|
let testDB = st.s.getDB(dbName);
|
let testColl = testDB.foo;
|
|
// Create a sharded collection with one chunk on shard0.
|
assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
|
assert.commandWorked(st.s.adminCommand({movePrimary: dbName, to: st.shard0.shardName}));
|
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {x: 1}}));
|
|
// After this there's only a chunk on shard 1
|
assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {x: 1}, to: st.shard1.shardName}));
|
|
// So this only creates an index on shard 1
|
assert.commandWorked(st.s.getCollection(ns).createIndex({x: 1, y: 1}));
|
|
// But this fails with "InvalidOptions: Please create an index that starts with the proposed shard key before sharding the collection" because it checks indexes on the primary shard (shard 0)
|
assert.commandWorked(st.s.adminCommand({refineCollectionShardKey: ns, key: {x: 1, y: 1}}));
|