Skip to content

Commit

Permalink
Merge pull request #5815 from Countly/anna/next
Browse files Browse the repository at this point in the history
[core] on findAndModify+remove transform object to return in expected format
  • Loading branch information
Cookiezaurs authored Nov 27, 2024
2 parents 753a720 + 45fb36b commit 91442bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
3 changes: 3 additions & 0 deletions plugins/pluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,9 @@ var pluginManager = function pluginManager() {
}
return function(err, res) {
if (res) {
if (!res.value && data && data.name === "findAndModify" && data.args && data.args[3] && data.args[3].remove) {
res = {"value": res};
}
if (!res.result) {
res.result = {};
}
Expand Down
39 changes: 10 additions & 29 deletions test/unit-tests/db.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down

0 comments on commit 91442bb

Please sign in to comment.