diff options
-rw-r--r-- | jstests/noPassthroughWithMongod/capped_truncate.js | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/test_commands.cpp | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/capped_truncate.js b/jstests/noPassthroughWithMongod/capped_truncate.js index 1c7771ce0bd..8408ea7294b 100644 --- a/jstests/noPassthroughWithMongod/capped_truncate.js +++ b/jstests/noPassthroughWithMongod/capped_truncate.js @@ -17,6 +17,13 @@ autoIndexId: true })); var t = db.capped_truncate; + // It is an error to remove a non-positive number of documents. + assert.commandFailed(db.runCommand({ captrunc: "capped_truncate", n: -1 }), + "captrunc didn't return an error when attempting to remove a negative " + + "number of documents"); + assert.commandFailed(db.runCommand({ captrunc: "capped_truncate", n: 0 }), + "captrunc didn't return an error when attempting to remove 0 documents"); + for (var j = 1; j <= 10; j++) { assert.writeOK(t.insert({x:j})); } diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index fcfafbf5607..485998c4e3a 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -228,6 +228,11 @@ public: int n = cmdObj.getIntField("n"); bool inc = cmdObj.getBoolField("inc"); // inclusive range? + if (n <= 0) { + return appendCommandStatus(result, + {ErrorCodes::BadValue, "n must be a positive integer"}); + } + OldClientWriteContext ctx(txn, fullNs); Collection* collection = ctx.getCollection(); |