summaryrefslogtreecommitdiff
path: root/jstests/sharding/shard_collection_basic.js
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-06-23 18:24:37 -0400
committerDavid Storch <david.storch@10gen.com>2016-06-27 17:55:36 -0400
commit424a411fa7c8d54c840719dec9af657a357c2578 (patch)
treea9f60ce1e0fc6cb1178e1e688234c2254736723b /jstests/sharding/shard_collection_basic.js
parent7fb4f0c57126bab6a0d2ea01d7e76926f64ca1e3 (diff)
downloadmongo-424a411fa7c8d54c840719dec9af657a357c2578.tar.gz
SERVER-24751 add collation parameter to shardCollection command
This parameter must be used to specify the simple collation when the collection has a non-simple default collation. Since the shard key is required to have the simple collation, we now enforce that there is an index whose prefix is the shard key and whose collation is the simple collation.
Diffstat (limited to 'jstests/sharding/shard_collection_basic.js')
-rw-r--r--jstests/sharding/shard_collection_basic.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/jstests/sharding/shard_collection_basic.js b/jstests/sharding/shard_collection_basic.js
index 769c2fc8163..ed2635ae791 100644
--- a/jstests/sharding/shard_collection_basic.js
+++ b/jstests/sharding/shard_collection_basic.js
@@ -150,6 +150,57 @@
assert.commandFailed(
mongos.adminCommand({shardCollection: kDbName + '.foo', key: {aKey: 1}, unique: true}));
+ //
+ // Collation-related tests
+ //
+
+ assert.commandWorked(mongos.getDB(kDbName).dropDatabase());
+ assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));
+
+ // shardCollection should fail when the 'collation' option is not a nested object.
+ assert.commandFailed(
+ mongos.adminCommand({shardCollection: kDbName + '.foo', key: {_id: 1}, collation: true}));
+
+ // shardCollection should fail when the 'collation' option cannot be parsed.
+ assert.commandFailed(mongos.adminCommand(
+ {shardCollection: kDbName + '.foo', key: {_id: 1}, collation: {locale: 'unknown'}}));
+
+ // shardCollection should fail when the 'collation' option is valid but is not the simple
+ // collation.
+ assert.commandFailed(mongos.adminCommand(
+ {shardCollection: kDbName + '.foo', key: {_id: 1}, collation: {locale: 'en_US'}}));
+
+ // shardCollection should succeed when the 'collation' option specifies the simple collation.
+ assert.commandWorked(mongos.adminCommand(
+ {shardCollection: kDbName + '.foo', key: {_id: 1}, collation: {locale: 'simple'}}));
+
+ // shardCollection should fail when it does not specify the 'collation' option but 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}}));
+
+ // shardCollection should succeed when it specifies the simple collation and 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.commandWorked(mongos.adminCommand(
+ {shardCollection: kDbName + '.foo', key: {_id: 1}, collation: {locale: 'simple'}}));
+
+ // shardCollection should fail when the only index available with the shard key as a prefix has
+ // a non-simple collation.
+ mongos.getDB(kDbName).foo.drop();
+ assert.commandWorked(
+ mongos.getDB(kDbName).createCollection('foo', {collation: {locale: 'en_US'}}));
+ // This index will inherit the collection's default collation.
+ assert.commandWorked(mongos.getDB(kDbName).foo.createIndex({a: 1}));
+ assert.commandWorked(mongos.adminCommand(
+ {shardCollection: kDbName + '.foo', key: {a: 1}, collation: {locale: 'simple'}}));
+
+ mongos.getDB(kDbName).dropDatabase();
+
st.stop();
})();