diff options
author | David Storch <david.storch@10gen.com> | 2015-02-26 11:22:34 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-03-09 12:48:29 -0400 |
commit | 98276a11bdbd5ef863f0fead63c14f5a7a13440d (patch) | |
tree | 6f9de2d35a16af5f8da446091f61b867e3a5eab8 /jstests/core/find_and_modify.js | |
parent | e8f722a0f2fa0b1550fc0bbdbd0aec1461a282ac (diff) | |
download | mongo-98276a11bdbd5ef863f0fead63c14f5a7a13440d.tar.gz |
SERVER-17387 prevent invalid projections from causing findAndModify to trigger a logOp() rollback
Diffstat (limited to 'jstests/core/find_and_modify.js')
-rw-r--r-- | jstests/core/find_and_modify.js | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/jstests/core/find_and_modify.js b/jstests/core/find_and_modify.js index d384f02b4bc..afaeda3d9a9 100644 --- a/jstests/core/find_and_modify.js +++ b/jstests/core/find_and_modify.js @@ -45,19 +45,81 @@ assert.throws(function() { t.findAndModify({query:{x:1}, update:{y:2}, remove:tr assert.throws(function() { t.findAndModify({query:{x:1}, update:{y:2}, new:true, remove:true}); }); assert.throws(function() { t.findAndModify({query:{x:1}, upsert:true, remove:true}); }); -// SERVER-17372 +// +// SERVER-17387: Find and modify should throw in the case of invalid projection. +// + t.drop(); + +// Insert case. var cmdRes = db.runCommand({ findAndModify: t.getName(), query: {_id: "miss"}, update: {$inc: {y: 1}}, + fields: {foo: {$pop: ["bar"]}}, + upsert: true, + new: true +}); +assert.commandFailed(cmdRes); + +t.insert({_id: "found"}); + +// Update with upsert + new. +cmdRes = db.runCommand({ + findAndModify: t.getName(), + query: {_id: "found"}, + update: {$inc: {y: 1}}, + fields: {foo: {$pop: ["bar"]}}, + upsert: true, + new: true +}); +assert.commandFailed(cmdRes); + +// Update with just new: true. +cmdRes = db.runCommand({ + findAndModify: t.getName(), + query: {_id: "found"}, + update: {$inc: {y: 1}}, + fields: {foo: {$pop: ["bar"]}}, + new: true +}); +assert.commandFailed(cmdRes); + +// Update with just upsert: true. +cmdRes = db.runCommand({ + findAndModify: t.getName(), + query: {_id: "found"}, + update: {$inc: {y: 1}}, + fields: {foo: {$pop: ["bar"]}}, + upsert: true +}); +assert.commandFailed(cmdRes); + +// Update with neither upsert nor new flags. +cmdRes = db.runCommand({ + findAndModify: t.getName(), + query: {_id: "found"}, + update: {$inc: {y: 1}}, + fields: {foo: {$pop: ["bar"]}}, +}); +assert.commandFailed(cmdRes); + +// +// SERVER-17372 +// + +t.drop(); +cmdRes = db.runCommand({ + findAndModify: t.getName(), + query: {_id: "miss"}, + update: {$inc: {y: 1}}, upsert: true }); assert.commandWorked(cmdRes); assert("value" in cmdRes); assert.eq(null, cmdRes.value); -var cmdRes = db.runCommand({ +cmdRes = db.runCommand({ findAndModify: t.getName(), query: {_id: "missagain"}, update: {$inc: {y: 1}}, |