From 9d455adde47de4ee5514a71786aa1b3c51380fb2 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 25 Sep 2019 11:11:07 -0700 Subject: [PATCH] test(update): repro #8166 --- test/model.update.test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/model.update.test.js b/test/model.update.test.js index 612a25f2513..dc2da0c1c5b 100644 --- a/test/model.update.test.js +++ b/test/model.update.test.js @@ -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); + }); + }); }); \ No newline at end of file