Skip to content

Commit

Permalink
fix(query): correctly handle $in and required for $pull and update …
Browse files Browse the repository at this point in the history
…validators

Fix #5744
  • Loading branch information
vkarpov15 committed Oct 28, 2017
1 parent 3b4211e commit 85821d9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/services/updateValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ module.exports = function(query, schema, castedDoc, options) {

for (var i = 0; i < numKeys; ++i) {
if (keys[i].charAt(0) === '$') {
if (keys[i] === '$push' || keys[i] === '$addToSet' ||
keys[i] === '$pull' || keys[i] === '$pullAll') {
hasDollarUpdate = true;
if (keys[i] === '$push' || keys[i] === '$addToSet') {
_keys = Object.keys(castedDoc[keys[i]]);
for (var ii = 0; ii < _keys.length; ++ii) {
currentUpdate = castedDoc[keys[i]][_keys[ii]];
Expand All @@ -55,14 +55,14 @@ module.exports = function(query, schema, castedDoc, options) {
for (var j = 0; j < numPaths; ++j) {
var updatedPath = paths[j].replace('.$.', '.0.');
updatedPath = updatedPath.replace(/\.\$$/, '.0');
if (keys[i] === '$set' || keys[i] === '$setOnInsert') {
if (keys[i] === '$set' || keys[i] === '$setOnInsert' ||
keys[i] === '$pull' || keys[i] === '$pullAll') {
updatedValues[updatedPath] = flat[paths[j]];
} else if (keys[i] === '$unset') {
updatedValues[updatedPath] = undefined;
}
updatedKeys[updatedPath] = true;
}
hasDollarUpdate = true;
}
}

Expand Down

0 comments on commit 85821d9

Please sign in to comment.