summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorYuhong Zhang <yuhong.zhang@mongodb.com>2022-04-26 03:30:11 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-26 22:49:28 +0000
commitb61476a952e1297436c8d9dbd72fc8d4f8b10da4 (patch)
tree2778fa3c003b2af04d0004c024dfd735c4ea42e2 /src/mongo/db/index
parentfcb9d766b6f66e6a9cfabe1795c1e9d43465b151 (diff)
downloadmongo-b61476a952e1297436c8d9dbd72fc8d4f8b10da4.tar.gz
SERVER-65922 Allow duplicate keys to be inserted before the index build with the `prepareUnique` option commits
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/index_access_method.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index dba2fb07af5..6de2aea381a 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -281,10 +281,9 @@ Status SortedDataIndexAccessMethod::insertKeys(OperationContext* opCtx,
// wiredtiger. See SERVER-59831.
dupsAllowed = true;
} else if (prepareUnique) {
- // This currently is only used by collMod command when converting a regular index to a
- // unique index. The regular index will start rejecting duplicates even before the
- // conversion finishes.
- dupsAllowed = false;
+ // Before the index build commits, duplicate keys are allowed to exist with the
+ // 'prepareUnique' option. After that, duplicates are not allowed.
+ dupsAllowed = !coll->isIndexReady(_descriptor->indexName());
} else {
dupsAllowed = !unique;
}