From c9cbea055905a98d2b7a2588523b74a38c84c66d Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 13 Nov 2024 11:53:01 -0500 Subject: [PATCH] test: add test showing that bulkWrite strips out keys that arent in schema by default re: code review on #15036 --- test/model.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/model.test.js b/test/model.test.js index 4aa6e6f1d2..1d5f4d44ea 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -4157,7 +4157,8 @@ describe('Model', function() { filter: { _id: r1._id }, update: { $set: { - 'testArray.$[element].field1': field1update + 'testArray.$[element].field1': field1update, + 'testArray.$[element].nonexistentProp': field1update } }, arrayFilters: [ @@ -4168,8 +4169,9 @@ describe('Model', function() { ] } }]); - const r2 = await TestModel.findById(r1._id); + const r2 = await TestModel.findById(r1._id).lean(); assert.equal(r2.testArray[0].field1, field1update); + assert.strictEqual(r2.testArray[0].nonexistentProp, undefined); }); it('with child timestamps and array filters (gh-7032)', async function() {