Files
mongo/jstests/core/query/explain/explain_delete.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.5 KiB
JavaScript
Raw Normal View History

/**
* Tests for explaining the delete command.
*
* @tags: [
* no_selinux,
* requires_fastcount,
* requires_fcv_61,
* requires_non_retryable_writes,
* # Pre-images requires doc-by-doc deletion and this test relies on BATCHED_DELETE
* incompatible_with_preimages_by_default,
* ]
*/
import {checkNWouldDelete} from "jstests/libs/query/analyze_plan.js";
let collName = "jstests_explain_delete";
let t = db[collName];
t.drop();
2014-09-18 14:06:54 -04:00
let explain;
2014-09-18 14:06:54 -04:00
// Explain delete against an empty collection.
assert.commandWorked(db.createCollection(t.getName()));
explain = db.runCommand({explain: {delete: collName, deletes: [{q: {a: 1}, limit: 0}]}});
checkNWouldDelete(explain, 0);
2014-09-18 14:06:54 -04:00
// Add an index but no data, and check that the explain still works.
t.createIndex({a: 1});
explain = db.runCommand({explain: {delete: collName, deletes: [{q: {a: 1}, limit: 0}]}});
checkNWouldDelete(explain, 0);
2014-09-18 14:06:54 -04:00
// Add some copies of the same document.
for (let i = 0; i < 10; i++) {
t.insert({a: 1});
}
assert.eq(10, t.count());
2014-09-18 14:06:54 -04:00
// Run an explain which shows that all 10 documents *would* be deleted.
explain = db.runCommand({explain: {delete: collName, deletes: [{q: {a: 1}, limit: 0}]}});
checkNWouldDelete(explain, 10);
2014-09-18 14:06:54 -04:00
// Make sure all 10 documents are still there.
assert.eq(10, t.count());
2014-09-18 14:06:54 -04:00
// If we run the same thing without the explain, then all 10 docs should be deleted.
let deleteResult = db.runCommand({delete: collName, deletes: [{q: {a: 1}, limit: 0}]});
assert.commandWorked(deleteResult);
assert.eq(0, t.count());