summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/create_collection_coordinator.cpp
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-03-14 16:18:28 +0000
commit0f28913257b0d6fee3b92927d7ec16a2ad54a0a0 (patch)
tree1caedee8a8fef474b7a72cb665acaf519afb58f7 /src/mongo/db/s/create_collection_coordinator.cpp
parent1512c333827379f6ae74a4e2cceeaadbe768ba04 (diff)
downloadmongo-0f28913257b0d6fee3b92927d7ec16a2ad54a0a0.tar.gz
SERVER-63732 Add new implicitlyCreateIndex and enforceUniqueness to shardCollection command
Diffstat (limited to 'src/mongo/db/s/create_collection_coordinator.cpp')
-rw-r--r--src/mongo/db/s/create_collection_coordinator.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp
index 76122d24165..eaf25a98659 100644
--- a/src/mongo/db/s/create_collection_coordinator.cpp
+++ b/src/mongo/db/s/create_collection_coordinator.cpp
@@ -759,13 +759,27 @@ void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext*
shardkeyutil::validateShardKeyIsNotEncrypted(opCtx, nss(), *_shardKeyPattern);
- const auto indexCreated = shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible(
- opCtx,
- nss(),
- *_shardKeyPattern,
- _collationBSON,
- _doc.getUnique().value_or(false),
- shardkeyutil::ValidationBehaviorsShardCollection(opCtx));
+ auto indexCreated = false;
+ if (_doc.getImplicitlyCreateIndex()) {
+ indexCreated = shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible(
+ opCtx,
+ nss(),
+ *_shardKeyPattern,
+ _collationBSON,
+ _doc.getUnique().value_or(false),
+ _doc.getEnforceUniquenessCheck(),
+ shardkeyutil::ValidationBehaviorsShardCollection(opCtx));
+ } else {
+ uassert(6373200,
+ "Must have an index compatible with the proposed shard key",
+ validShardKeyIndexExists(opCtx,
+ nss(),
+ *_shardKeyPattern,
+ _collationBSON,
+ _doc.getUnique().value_or(false) &&
+ _doc.getEnforceUniquenessCheck(),
+ shardkeyutil::ValidationBehaviorsShardCollection(opCtx)));
+ }
auto replClientInfo = repl::ReplClientInfo::forClient(opCtx->getClient());