Skip to content

Commit 3b4211e

Browse files
committed
test(query): repro #5744
1 parent b9ab446 commit 3b4211e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

test/model.update.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,7 @@ describe('model: update:', function() {
27112711

27122712
User.update({}, update, opts).exec(function(error) {
27132713
assert.ok(error);
2714-
assert.ok(error.errors['notifications']);
2714+
assert.ok(error.errors['notifications.message']);
27152715

27162716
update.$pull.notifications.message = 'test';
27172717
User.update({ _id: doc._id }, update, opts).exec(function(error) {
@@ -2726,6 +2726,36 @@ describe('model: update:', function() {
27262726
});
27272727
});
27282728

2729+
it('$pull with updateValidators and $in (gh-5744)', function(done) {
2730+
var exampleSchema = mongoose.Schema({
2731+
subdocuments: [{
2732+
name: String
2733+
}]
2734+
});
2735+
var ExampleModel = db.model('gh5744', exampleSchema);
2736+
var exampleDocument = {
2737+
subdocuments: [{ name: 'First' }, { name: 'Second' }]
2738+
};
2739+
2740+
ExampleModel.create(exampleDocument, function(error, doc) {
2741+
assert.ifError(error);
2742+
ExampleModel.updateOne({ _id: doc._id }, {
2743+
$pull: {
2744+
subdocuments: {
2745+
_id: { $in: [doc.subdocuments[0]._id] }
2746+
}
2747+
}
2748+
}, { runValidators: true }, function(error) {
2749+
assert.ifError(error);
2750+
ExampleModel.findOne({ _id: doc._id }, function(error, doc) {
2751+
assert.ifError(error);
2752+
assert.equal(doc.subdocuments.length, 1);
2753+
done();
2754+
});
2755+
});
2756+
});
2757+
});
2758+
27292759
it('update with Decimal type (gh-5361)', function(done) {
27302760
start.mongodVersion(function(err, version) {
27312761
if (err) {

0 commit comments

Comments
 (0)