From 5a71c4fca613b18b61ab0def1d202ab3ac888b88 Mon Sep 17 00:00:00 2001 From: Cookiezaurs <> Date: Wed, 27 Nov 2024 17:11:26 +0200 Subject: [PATCH 1/3] [core] on findAndModify+remove transform object to return in expected format --- plugins/pluginManager.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/pluginManager.js b/plugins/pluginManager.js index 8df7214face..388dbc538bc 100644 --- a/plugins/pluginManager.js +++ b/plugins/pluginManager.js @@ -2344,6 +2344,9 @@ var pluginManager = function pluginManager() { } return function(err, res) { if (res) { + if (!res.value && data.name === "findAndModify" && data && data.args && data.args[3] && data.args[3].remove) { + res = {"value": res}; + } if (!res.result) { res.result = {}; } From 98bbaab8e8ddc9393de40582bbf275b53b0dc604 Mon Sep 17 00:00:00 2001 From: Cookiezaurs <> Date: Wed, 27 Nov 2024 18:13:45 +0200 Subject: [PATCH 2/3] fixed tests --- test/unit-tests/db.tests.js | 39 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/test/unit-tests/db.tests.js b/test/unit-tests/db.tests.js index 05928ad0a24..631e1ee9c01 100644 --- a/test/unit-tests/db.tests.js +++ b/test/unit-tests/db.tests.js @@ -27,40 +27,21 @@ function runTest(options) { db.collection("testCommands").findAndModify(options.query, options.sort || {}, options.update, options.options, function(err, res) { should.not.exist(err); console.log(JSON.stringify(res)); - - - if (options.options.remove) { - res = res || {}; - if (options.query._id) { - res.should.have.property("_id", options.query._id); - } - else { - res.should.have.property("_id"); - } - - if (options.query.name) { - res.should.have.property("name", options.query.name); - } - else { - res.should.have.property("name"); + res.should.have.property("value"); + if (options.options.new) { + if (options.update.$set.name) { + res.value.should.have.property("name", options.update.$set.name); } } else { - res.should.have.property("value"); - if (options.options.new) { - if (options.update.$set.name) { - res.value.should.have.property("name", options.update.$set.name); - } - } - else { - if (options.query.name) { - res.value.should.have.property("name", options.query.name); - } - } - if (options.query._id) { - res.value.should.have.property("_id", options.query._id); + if (options.query.name) { + res.value.should.have.property("name", options.query.name); } } + if (options.query._id) { + res.value.should.have.property("_id", options.query._id); + } + done(); }); } From 45fb36b7b84e9b97fe98dadb62967334310c1331 Mon Sep 17 00:00:00 2001 From: Anna Sosina Date: Wed, 27 Nov 2024 18:26:18 +0200 Subject: [PATCH 3/3] code quality --- plugins/pluginManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pluginManager.js b/plugins/pluginManager.js index 388dbc538bc..7211fa3d847 100644 --- a/plugins/pluginManager.js +++ b/plugins/pluginManager.js @@ -2344,7 +2344,7 @@ var pluginManager = function pluginManager() { } return function(err, res) { if (res) { - if (!res.value && data.name === "findAndModify" && data && data.args && data.args[3] && data.args[3].remove) { + if (!res.value && data && data.name === "findAndModify" && data.args && data.args[3] && data.args[3].remove) { res = {"value": res}; } if (!res.result) {