Skip to content

Commit 91442bb

Browse files
authored
Merge pull request #5815 from Countly/anna/next
[core] on findAndModify+remove transform object to return in expected format
2 parents 753a720 + 45fb36b commit 91442bb

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

plugins/pluginManager.js

+3
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,9 @@ var pluginManager = function pluginManager() {
23442344
}
23452345
return function(err, res) {
23462346
if (res) {
2347+
if (!res.value && data && data.name === "findAndModify" && data.args && data.args[3] && data.args[3].remove) {
2348+
res = {"value": res};
2349+
}
23472350
if (!res.result) {
23482351
res.result = {};
23492352
}

test/unit-tests/db.tests.js

+10-29
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,21 @@ function runTest(options) {
2727
db.collection("testCommands").findAndModify(options.query, options.sort || {}, options.update, options.options, function(err, res) {
2828
should.not.exist(err);
2929
console.log(JSON.stringify(res));
30-
31-
32-
if (options.options.remove) {
33-
res = res || {};
34-
if (options.query._id) {
35-
res.should.have.property("_id", options.query._id);
36-
}
37-
else {
38-
res.should.have.property("_id");
39-
}
40-
41-
if (options.query.name) {
42-
res.should.have.property("name", options.query.name);
43-
}
44-
else {
45-
res.should.have.property("name");
30+
res.should.have.property("value");
31+
if (options.options.new) {
32+
if (options.update.$set.name) {
33+
res.value.should.have.property("name", options.update.$set.name);
4634
}
4735
}
4836
else {
49-
res.should.have.property("value");
50-
if (options.options.new) {
51-
if (options.update.$set.name) {
52-
res.value.should.have.property("name", options.update.$set.name);
53-
}
54-
}
55-
else {
56-
if (options.query.name) {
57-
res.value.should.have.property("name", options.query.name);
58-
}
59-
}
60-
if (options.query._id) {
61-
res.value.should.have.property("_id", options.query._id);
37+
if (options.query.name) {
38+
res.value.should.have.property("name", options.query.name);
6239
}
6340
}
41+
if (options.query._id) {
42+
res.value.should.have.property("_id", options.query._id);
43+
}
44+
6445
done();
6546
});
6647
}

0 commit comments

Comments
 (0)