Skip to content

Commit

Permalink
test(update): repro #8166
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 25, 2019
1 parent 8c98a3a commit 9d455ad
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/model.update.test.js
Expand Up @@ -3315,4 +3315,37 @@ describe('model: updateOne: ', function() {
assert.equal(doc.test, 'after');
});
});

it('allow $pull with non-existent schema field (gh-8166)', function() {
const Model = db.model('gh8166', Schema({
name: String,
arr: [{
status: String,
values: [{ text: String }]
}]
}));

return co(function*() {
yield Model.collection.insertMany([
{
name: 'a',
arr: [{ values: [{ text: '123' }] }]
},
{
name: 'b',
arr: [{ values: [{ text: '123', coords: 'test' }] }]
}
]);

yield Model.updateMany({}, {
$pull: { arr: { 'values.0.coords': { $exists: false } } }
});

const docs = yield Model.find().sort({ name: 1 });
assert.equal(docs[0].name, 'a');
assert.equal(docs[0].arr.length, 0);
assert.equal(docs[1].name, 'b');
assert.equal(docs[1].arr.length, 1);
});
});
});

0 comments on commit 9d455ad

Please sign in to comment.