Skip to content

Commit a61f4d7

Browse files
authored
Merge pull request #6467 from lineus/fix-6439-v4
add fix for #6439 to 4.x
2 parents cd2a15a + 48f1fc3 commit a61f4d7

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/services/query/castUpdate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function walkUpdatePath(schema, obj, op, strict, context, pref) {
193193
(utils.isObject(val) && Object.keys(val).length === 0);
194194
}
195195
} else {
196-
var checkPath = (key === '$each' || key === '$or' || key === '$and') ?
196+
var checkPath = (key === '$each' || key === '$or' || key === '$and' || key === '$in') ?
197197
pref : prefix + key;
198198
schematype = schema._getSchema(checkPath);
199199

test/query.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,50 @@ describe('Query', function() {
918918
done();
919919
});
920920

921+
it('doesn\'t wipe out $in (gh-6439)', function(done) {
922+
var embeddedSchema = new Schema({
923+
name: String
924+
}, { _id: false });
925+
926+
var catSchema = new Schema({
927+
name: String,
928+
props: [embeddedSchema]
929+
});
930+
931+
var Cat = db.model('gh6439', catSchema);
932+
var kitty = new Cat({
933+
name: 'Zildjian',
934+
props: [
935+
{ name: 'invalid' },
936+
{ name: 'abc' },
937+
{ name: 'def' }
938+
]
939+
});
940+
941+
kitty.save(function(err) {
942+
assert.ifError(err);
943+
var cond = { _id: kitty._id };
944+
var update = {
945+
$pull: {
946+
props: {
947+
$in: [
948+
{ name: 'invalid' },
949+
{ name: 'def' }
950+
]
951+
}
952+
}
953+
};
954+
Cat.update(cond, update, function(err) {
955+
assert.ifError(err);
956+
Cat.findOne(cond, function(err, found) {
957+
assert.ifError(err);
958+
assert.strictEqual(found.props[0].name, 'abc');
959+
done();
960+
});
961+
});
962+
});
963+
});
964+
921965
it('subdocument array with $ne: null should not throw', function(done) {
922966
var query = new Query({}, {}, null, p1.collection);
923967
var Product = db.model('Product');

0 commit comments

Comments
 (0)