Skip to content

Commit

Permalink
add fix for #6439 to 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
lineus committed May 13, 2018
1 parent cd2a15a commit 06cca17
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/services/query/castUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function walkUpdatePath(schema, obj, op, strict, context, pref) {
(utils.isObject(val) && Object.keys(val).length === 0);
}
} else {
var checkPath = (key === '$each' || key === '$or' || key === '$and') ?
var checkPath = (key === '$each' || key === '$or' || key === '$and' || key === '$in') ?
pref : prefix + key;
schematype = schema._getSchema(checkPath);

Expand Down
40 changes: 40 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Schema = mongoose.Schema;
var assert = require('power-assert');
var random = require('../lib/utils').random;
var Query = require('../lib/query');
var co = require('co');

/**
* Test.
Expand Down Expand Up @@ -918,6 +919,45 @@ describe('Query', function() {
done();
});

it('doesn\'t wipe out $in (gh-6439)', function () {
var embeddedSchema = new Schema({
name: String
}, { _id: false });

var catSchema = new Schema({
name: String,
props: [embeddedSchema]
});

var Cat = db.model('gh6439', catSchema);
var kitty = new Cat({
name: 'Zildjian',
props: [
{ name: 'invalid' },
{ name: 'abc' },
{ name: 'def' }
]
});

return co(function* () {
yield kitty.save();
var cond = { _id: kitty._id };
var update = {
$pull: {
props: {
$in: [
{ name: 'invalid' },
{ name: 'def' }
]
}
}
};
yield Cat.update(cond, update);
let found = yield Cat.findOne(cond);
assert.strictEqual(found.props[0].name, 'abc');
});
});

it('subdocument array with $ne: null should not throw', function(done) {
var query = new Query({}, {}, null, p1.collection);
var Product = db.model('Product');
Expand Down

0 comments on commit 06cca17

Please sign in to comment.