diff options
author | clang-format-7.0.1 <adam.martin@10gen.com> | 2019-07-26 18:20:35 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-07-27 11:02:23 -0400 |
commit | 134a4083953270e8a11430395357fb70a29047ad (patch) | |
tree | dd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /jstests/core/update_modifier_pop.js | |
parent | 1e46b5049003f427047e723ea5fab15b5a9253ca (diff) | |
download | mongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz |
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'jstests/core/update_modifier_pop.js')
-rw-r--r-- | jstests/core/update_modifier_pop.js | 217 |
1 files changed, 107 insertions, 110 deletions
diff --git a/jstests/core/update_modifier_pop.js b/jstests/core/update_modifier_pop.js index c74d7f254bf..77c6bae702c 100644 --- a/jstests/core/update_modifier_pop.js +++ b/jstests/core/update_modifier_pop.js @@ -1,115 +1,112 @@ // @tags: [requires_non_retryable_writes] (function() { - "use strict"; - - let coll = db.update_modifier_pop; - coll.drop(); - - assert.writeOK(coll.insert({_id: 0})); - - // $pop with value of 0 fails to parse. - assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": 0}}), ErrorCodes.FailedToParse); - - // $pop with value of -2 fails to parse. - assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": -2}}), ErrorCodes.FailedToParse); - - // $pop with value of 2.5 fails to parse. - assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": 2.5}}), - ErrorCodes.FailedToParse); - - // $pop with value of 1.1 fails to parse. - assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": 1.1}}), - ErrorCodes.FailedToParse); - - // $pop with a nested object fails to parse. - assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {a: {b: 1}}}), ErrorCodes.FailedToParse); - - // $pop is a no-op when the path does not exist. - let writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); - assert.eq(writeRes.nMatched, 1); - if (db.getMongo().writeMode() === "commands") { - assert.eq(writeRes.nModified, 0); - } - - // $pop is a no-op when the path partially exists. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: {c: 1}})); - writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); - assert.eq(writeRes.nMatched, 1); - if (db.getMongo().writeMode() === "commands") { - assert.eq(writeRes.nModified, 0); - } - - // $pop fails when the path is blocked by a scalar element. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: {b: 1}})); - assert.writeError(coll.update({_id: 0}, {$pop: {"a.b.c": 1}})); - - // $pop fails when the path is blocked by an array element. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: {b: [1, 2]}})); - assert.writeError(coll.update({_id: 0}, {$pop: {"a.b.c": 1}})); - - // $pop fails when the path exists but is not an array. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: {b: {c: 1}}})); - assert.writeError(coll.update({_id: 0}, {$pop: {"a.b": 1}})); - - // $pop is a no-op when the path contains an empty array. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: {b: []}})); - writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); - assert.eq(writeRes.nMatched, 1); - if (db.getMongo().writeMode() === "commands") { - assert.eq(writeRes.nModified, 0); - } - - // Successfully pop from the end of an array. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: {b: [1, 2, 3]}})); - writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); - assert.eq(writeRes.nMatched, 1); - if (db.getMongo().writeMode() === "commands") { - assert.eq(writeRes.nModified, 1); - } - assert.eq({_id: 0, a: {b: [1, 2]}}, coll.findOne()); - - // Successfully pop from the beginning of an array. - writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": -1}})); - assert.eq(writeRes.nMatched, 1); - if (db.getMongo().writeMode() === "commands") { - assert.eq(writeRes.nModified, 1); - } - assert.eq({_id: 0, a: {b: [2]}}, coll.findOne()); - - // $pop with the positional ($) operator. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: [{b: [1, 2, 3]}, {b: [4, 5, 6]}]})); - assert.writeOK(coll.update({_id: 0, "a.b": 5}, {$pop: {"a.$.b": 1}})); - assert.eq({_id: 0, a: [{b: [1, 2, 3]}, {b: [4, 5]}]}, coll.findOne()); - - // $pop with arrayFilters. - if (db.getMongo().writeMode() === "commands") { - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: [{b: [1, 2]}, {b: [4, 5]}, {b: [2, 3]}]})); - assert.writeOK( - coll.update({_id: 0}, {$pop: {"a.$[i].b": -1}}, {arrayFilters: [{"i.b": 2}]})); - assert.eq({_id: 0, a: [{b: [2]}, {b: [4, 5]}, {b: [3]}]}, coll.findOne()); - } - - // $pop from a nested array. - assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: [1, [2, 3, 4]]})); - assert.writeOK(coll.update({_id: 0}, {$pop: {"a.1": 1}})); - assert.eq({_id: 0, a: [1, [2, 3]]}, coll.findOne()); - - // $pop is a no-op when array element in path does not exist. +"use strict"; + +let coll = db.update_modifier_pop; +coll.drop(); + +assert.writeOK(coll.insert({_id: 0})); + +// $pop with value of 0 fails to parse. +assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": 0}}), ErrorCodes.FailedToParse); + +// $pop with value of -2 fails to parse. +assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": -2}}), ErrorCodes.FailedToParse); + +// $pop with value of 2.5 fails to parse. +assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": 2.5}}), ErrorCodes.FailedToParse); + +// $pop with value of 1.1 fails to parse. +assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {"a.b": 1.1}}), ErrorCodes.FailedToParse); + +// $pop with a nested object fails to parse. +assert.writeErrorWithCode(coll.update({_id: 0}, {$pop: {a: {b: 1}}}), ErrorCodes.FailedToParse); + +// $pop is a no-op when the path does not exist. +let writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); +assert.eq(writeRes.nMatched, 1); +if (db.getMongo().writeMode() === "commands") { + assert.eq(writeRes.nModified, 0); +} + +// $pop is a no-op when the path partially exists. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: {c: 1}})); +writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); +assert.eq(writeRes.nMatched, 1); +if (db.getMongo().writeMode() === "commands") { + assert.eq(writeRes.nModified, 0); +} + +// $pop fails when the path is blocked by a scalar element. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: {b: 1}})); +assert.writeError(coll.update({_id: 0}, {$pop: {"a.b.c": 1}})); + +// $pop fails when the path is blocked by an array element. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: {b: [1, 2]}})); +assert.writeError(coll.update({_id: 0}, {$pop: {"a.b.c": 1}})); + +// $pop fails when the path exists but is not an array. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: {b: {c: 1}}})); +assert.writeError(coll.update({_id: 0}, {$pop: {"a.b": 1}})); + +// $pop is a no-op when the path contains an empty array. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: {b: []}})); +writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); +assert.eq(writeRes.nMatched, 1); +if (db.getMongo().writeMode() === "commands") { + assert.eq(writeRes.nModified, 0); +} + +// Successfully pop from the end of an array. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: {b: [1, 2, 3]}})); +writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": 1}})); +assert.eq(writeRes.nMatched, 1); +if (db.getMongo().writeMode() === "commands") { + assert.eq(writeRes.nModified, 1); +} +assert.eq({_id: 0, a: {b: [1, 2]}}, coll.findOne()); + +// Successfully pop from the beginning of an array. +writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.b": -1}})); +assert.eq(writeRes.nMatched, 1); +if (db.getMongo().writeMode() === "commands") { + assert.eq(writeRes.nModified, 1); +} +assert.eq({_id: 0, a: {b: [2]}}, coll.findOne()); + +// $pop with the positional ($) operator. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: [{b: [1, 2, 3]}, {b: [4, 5, 6]}]})); +assert.writeOK(coll.update({_id: 0, "a.b": 5}, {$pop: {"a.$.b": 1}})); +assert.eq({_id: 0, a: [{b: [1, 2, 3]}, {b: [4, 5]}]}, coll.findOne()); + +// $pop with arrayFilters. +if (db.getMongo().writeMode() === "commands") { assert.writeOK(coll.remove({})); - assert.writeOK(coll.insert({_id: 0, a: [{b: 0}, {b: 1}]})); - writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.2.b": 1}})); - assert.eq(writeRes.nMatched, 1); - if (db.getMongo().writeMode() === "commands") { - assert.eq(writeRes.nModified, 0); - } + assert.writeOK(coll.insert({_id: 0, a: [{b: [1, 2]}, {b: [4, 5]}, {b: [2, 3]}]})); + assert.writeOK(coll.update({_id: 0}, {$pop: {"a.$[i].b": -1}}, {arrayFilters: [{"i.b": 2}]})); + assert.eq({_id: 0, a: [{b: [2]}, {b: [4, 5]}, {b: [3]}]}, coll.findOne()); +} + +// $pop from a nested array. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: [1, [2, 3, 4]]})); +assert.writeOK(coll.update({_id: 0}, {$pop: {"a.1": 1}})); +assert.eq({_id: 0, a: [1, [2, 3]]}, coll.findOne()); + +// $pop is a no-op when array element in path does not exist. +assert.writeOK(coll.remove({})); +assert.writeOK(coll.insert({_id: 0, a: [{b: 0}, {b: 1}]})); +writeRes = assert.writeOK(coll.update({_id: 0}, {$pop: {"a.2.b": 1}})); +assert.eq(writeRes.nMatched, 1); +if (db.getMongo().writeMode() === "commands") { + assert.eq(writeRes.nModified, 0); +} }()); |