summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/batched_multi_deletes_single_oplog.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/batched_multi_deletes_single_oplog.js')
-rw-r--r--jstests/noPassthrough/batched_multi_deletes_single_oplog.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/jstests/noPassthrough/batched_multi_deletes_single_oplog.js b/jstests/noPassthrough/batched_multi_deletes_single_oplog.js
new file mode 100644
index 00000000000..cffd250ffbb
--- /dev/null
+++ b/jstests/noPassthrough/batched_multi_deletes_single_oplog.js
@@ -0,0 +1,46 @@
+/**
+ * Tests that batch deletes resulting with single operations create regular delete oplog entries.
+ *
+ * @tags: [
+ * requires_replication,
+ * ]
+ */
+(function() {
+'use strict';
+
+const dbName = jsTestName();
+const collName = "test";
+const collCount = 10;
+
+const rst = new ReplSetTest({nodes: 1});
+rst.startSet();
+rst.initiate();
+
+const primary = rst.getPrimary();
+const db = primary.getDB(dbName);
+const coll = db.getCollection(collName);
+coll.drop();
+
+assert.commandWorked(coll.insertMany([...Array(collCount).keys()].map(x => ({_id: x, a: x}))));
+assert.eq(collCount, coll.countDocuments({}));
+
+// Verify the delete will involve the BATCHED_DELETE stage.
+const expl = db.runCommand({
+ explain: {delete: coll.getName(), deletes: [{q: {_id: {$lte: 0}}, limit: 0}]},
+ verbosity: "executionStats"
+});
+assert.commandWorked(expl);
+assert.eq(expl["queryPlanner"]["winningPlan"]["stage"], "BATCHED_DELETE");
+
+jsTestLog("Deleting all documents where _id <= 0");
+assert.commandWorked(coll.deleteMany({_id: {$lte: 0}}));
+
+let ops =
+ rst.findOplog(primary, {op: 'c', ns: 'admin.$cmd', 'o.applyOps': {$exists: true}}).toArray();
+assert.eq(0, ops.length, "Should not have an applyOps oplog entry: " + tojson(ops));
+
+ops = rst.findOplog(primary, {op: 'd', ns: coll.getFullName(), o: {_id: 0}}).toArray();
+assert.eq(1, ops.length, "Should have a delete oplog entry: " + tojson(ops));
+
+rst.stopSet();
+})();