Files
mongo/jstests/core/index/unique_index_insert.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

36 lines
941 B
JavaScript

/**
* Regression test confirming unique index constraints are upheld. See SERVER-58943 for details.
*
* @tags: [
* cannot_create_unique_index_when_using_hashed_shard_key,
* does_not_support_transactions,
* requires_getmore,
* ]
*/
const dbName = "unique_index_insert";
const collName = "test";
const testDB = db.getSiblingDB("unique_index_insert");
testDB[collName].drop();
const coll = testDB[collName];
assert.commandWorked(coll.createIndex({i: 1, x: -1}, {unique: true}));
const n = 100;
const xStr = "x".repeat(50000);
const bulk = coll.initializeUnorderedBulkOp();
for (let i = 0; i < n; i++) {
bulk.insert({i, x: xStr});
}
assert.commandWorked(bulk.execute());
assert.eq(coll.find().itcount(), 100);
const maxIters = 2;
for (let iter = 0; iter < maxIters; iter++) {
for (let i = 0; i < n; i++) {
assert.commandFailed(coll.insert({i, x: xStr}), `Failed with i ${i}, iter ${iter}`);
}
}