summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2022-03-14 15:23:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-25 15:39:48 +0000
commit411a12ad600733fc80d9b6e8da86da51dd415ab0 (patch)
tree8626ab4c5efb31d464ac856b4ec54e52aa48ebb8 /jstests
parent5ce288636e0108dac375f0ec58eb6524d9899376 (diff)
downloadmongo-411a12ad600733fc80d9b6e8da86da51dd415ab0.tar.gz
SERVER-63732 Add new implicitlyCreateIndex and enforceUniqueness to shardCollection command
(cherry picked from commit 0f28913257b0d6fee3b92927d7ec16a2ad54a0a0)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/sharding/shard_collection_basic.js32
1 files changed, 31 insertions, 1 deletions
diff --git a/jstests/sharding/shard_collection_basic.js b/jstests/sharding/shard_collection_basic.js
index 877df390af6..359cb6c94f2 100644
--- a/jstests/sharding/shard_collection_basic.js
+++ b/jstests/sharding/shard_collection_basic.js
@@ -103,6 +103,12 @@ assert.commandFailed(
assert.commandWorked(
mongos.adminCommand({shardCollection: kDbName + '.shard_key_dotted_path', key: {'_id.a': 1}}));
+jsTestLog('Command should still verify index even if implicitlyCreateIndex is false.');
+assert.commandFailedWithCode(
+ mongos.adminCommand(
+ {shardCollection: kDbName + '.foo', key: {x: 1}, implicitlyCreateIndex: false}),
+ 6373200);
+
//
// Test shardCollection's idempotency
//
@@ -124,7 +130,31 @@ assert.commandFailed(
assert.commandWorked(mongos.getDB(kDbName).dropDatabase());
-// Shard empty collections no index required.
+jsTestLog('Allow non-unique index if enforceUniquenessCheck is false');
+assert.commandWorked(mongos.getDB(kDbName).foo.createIndex({x: 1}));
+assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));
+assert.commandWorked(mongos.adminCommand(
+ {shardCollection: kDbName + '.foo', key: {x: 1}, unique: true, enforceUniquenessCheck: false}));
+let collDoc = mongos.getDB('config').collections.findOne({_id: `${kDbName}.foo`});
+assert(collDoc);
+assert(collDoc.unique);
+assert.commandWorked(mongos.getDB(kDbName).dropDatabase());
+
+jsTestLog('mongosync unique key pattern use case');
+assert.commandWorked(mongos.getDB(kDbName).foo.createIndex({x: 1}));
+assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));
+assert.commandWorked(mongos.adminCommand({
+ shardCollection: kDbName + '.foo',
+ key: {x: 1},
+ unique: true,
+ implicitlyCreateIndex: false,
+ enforceUniquenessCheck: false
+}));
+collDoc = mongos.getDB('config').collections.findOne({_id: `${kDbName}.foo`});
+assert(collDoc);
+assert(collDoc.unique);
+assert.commandWorked(mongos.getDB(kDbName).dropDatabase());
+
testAndClenaupWithKeyNoIndexOK({_id: 1});
testAndClenaupWithKeyNoIndexOK({_id: 'hashed'});