diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-08-10 16:23:11 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-08-11 18:46:29 -0400 |
commit | 844007a979a51a1c7dd49c874f0c50cb66482360 (patch) | |
tree | 87556e2fa11e1713ca9dc584004c382c771094d3 /jstests/sharding/shard_collection_basic.js | |
parent | 52cd830b7186f218c296222b89bafe3f1abe932e (diff) | |
download | mongo-844007a979a51a1c7dd49c874f0c50cb66482360.tar.gz |
SERVER-24239 shardCollection should use simple collation when creating shard key index
Diffstat (limited to 'jstests/sharding/shard_collection_basic.js')
-rw-r--r-- | jstests/sharding/shard_collection_basic.js | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/jstests/sharding/shard_collection_basic.js b/jstests/sharding/shard_collection_basic.js index 0b99055ed6c..def763969c7 100644 --- a/jstests/sharding/shard_collection_basic.js +++ b/jstests/sharding/shard_collection_basic.js @@ -44,6 +44,14 @@ mongos.getDB(kDbName).dropDatabase(); } + function getIndexSpecByName(coll, indexName) { + var indexes = coll.getIndexes().filter(function(spec) { + return spec.name === indexName; + }); + assert.eq(1, indexes.length, 'index "' + indexName + '" not found"'); + return indexes[0]; + } + // Fail if db is not sharded. assert.commandFailed(mongos.adminCommand({shardCollection: kDbName + '.foo', key: {_id: 1}})); @@ -179,17 +187,40 @@ mongos.getDB(kDbName).foo.drop(); assert.commandWorked( mongos.getDB(kDbName).createCollection('foo', {collation: {locale: 'en_US'}})); - assert.commandFailed(mongos.adminCommand({shardCollection: kDbName + '.foo', key: {_id: 1}})); + assert.commandFailed(mongos.adminCommand({shardCollection: kDbName + '.foo', key: {a: 1}})); + + // shardCollection should fail for the key pattern {_id: 1} if the collection has a non-simple + // default collation. + mongos.getDB(kDbName).foo.drop(); + assert.commandWorked( + mongos.getDB(kDbName).createCollection('foo', {collation: {locale: 'en_US'}})); + assert.commandFailed(mongos.adminCommand( + {shardCollection: kDbName + '.foo', key: {_id: 1}, collation: {locale: 'simple'}})); - // TODO SERVER-24239: - // Test that shardCollection for the key pattern {_id: 1} fails if there is a non-simple - // collection default collation. - // Test that shardCollection for the key pattern {a: 1} fails if there is already an index 'a_1' + // shardCollection should fail for the key pattern {a: 1} if there is already an index 'a_1', // but it has a non-simple collation. - // Test that shardCollection for the key pattern {a: 1} and collation {locale: 'simple'} - // succeeds if there is no index 'a_1', but there is a non-simple collection default collation. - // Test that shardCollection for the key pattern {a: 1} and collation {locale: 'simple'} - // succeeds if there are two indexes on {a: 1} and one has the simple collation. + mongos.getDB(kDbName).foo.drop(); + assert.commandWorked( + mongos.getDB(kDbName).foo.createIndex({a: 1}, {collation: {locale: 'en_US'}})); + assert.commandFailed(mongos.adminCommand({shardCollection: kDbName + '.foo', key: {a: 1}})); + + // shardCollection should succeed for the key pattern {a: 1} and collation {locale: 'simple'} if + // there is no index 'a_1', but there is a non-simple collection default collation. + mongos.getDB(kDbName).foo.drop(); + assert.commandWorked( + mongos.getDB(kDbName).createCollection('foo', {collation: {locale: 'en_US'}})); + assert.commandWorked(mongos.adminCommand( + {shardCollection: kDbName + '.foo', key: {a: 1}, collation: {locale: 'simple'}})); + var indexSpec = getIndexSpecByName(mongos.getDB(kDbName).foo, 'a_1'); + assert(!indexSpec.hasOwnProperty('collation')); + + // shardCollection should succeed for the key pattern {a: 1} if there are two indexes on {a: 1} + // and one has the simple collation. + mongos.getDB(kDbName).foo.drop(); + assert.commandWorked(mongos.getDB(kDbName).foo.createIndex({a: 1}, {name: "a_1_simple"})); + assert.commandWorked(mongos.getDB(kDbName).foo.createIndex( + {a: 1}, {collation: {locale: 'en_US'}, name: "a_1_en_US"})); + assert.commandWorked(mongos.adminCommand({shardCollection: kDbName + '.foo', key: {a: 1}})); // shardCollection should fail on a non-empty collection when the only index available with the // shard key as a prefix has a non-simple collation. |