Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fix for #6439 to 4.x #6467

Merged
merged 2 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 44 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,50 @@ describe('Query', function() {
done();
});

it('doesn\'t wipe out $in (gh-6439)', function(done) {
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' }
]
});

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

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