Files
mongo/jstests/core/query/delete/remove_many.js
Mihai Andrei 5ed8f7dcf5 SERVER-93427 Move query writing tests from jstests/core/write to jstests/core/query (#31702)
GitOrigin-RevId: 2d69ca12e591fda58c4a5387ffae9d97c0ef2283
2025-02-04 19:38:51 +00:00

33 lines
983 B
JavaScript

// @tags: [requires_non_retryable_writes, requires_fastcount]
// Test removal of a substantial proportion of inserted documents.
const t = db[jsTestName()];
Random.setRandomSeed();
for (let v = 0; v < 2; ++v) { // Try each index version.
t.drop();
const indexCreateRes = t.createIndex({a: 1}, {v: v});
if (v === 0) {
assert.commandFailedWithCode(indexCreateRes, ErrorCodes.CannotCreateIndex);
} else {
assert.commandWorked(indexCreateRes);
}
const S = 100;
const B = 100;
for (let x = 0; x < S; x++) {
let batch = [];
for (let y = 0; y < B; y++) {
let i = y + (B * x);
batch.push({a: i});
}
assert.commandWorked(t.insert(batch));
}
assert.eq(t.count(), S * B);
let toDrop = [];
for (let i = 0; i < S * B; ++i) {
toDrop.push(Random.randInt(10000)); // Dups in the query will be ignored.
}
assert.commandWorked(t.remove({a: {$in: toDrop}}));
}