From 4d871c7b135c582b605e9a124e15952d52b9452a Mon Sep 17 00:00:00 2001 From: Hafez Date: Sat, 11 Apr 2020 18:53:07 +0200 Subject: [PATCH] test: repro #8778 --- test/model.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/model.test.js b/test/model.test.js index 400538bef86..b1a923c5a73 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -6563,4 +6563,30 @@ describe('Model', function() { assert.deepEqual(users[1].updatedAt, usersAfterUpdate[1].updatedAt); }); }); + + it('bulkWrite can overwrite schema `strict` option (gh-8778)', function() { + const userSchema = new Schema({ + name: String + }, { strict: true }); + + const User = db.model('User', userSchema); + + return co(function*() { + const users = yield User.create([{ name: 'Hafez1' }, { name: 'Hafez2' }]); + + yield User.bulkWrite([ + { updateOne: { filter: { _id: users[0]._id }, update: { notInSchema: 1 } } }, + { updateMany: { filter: { _id: users[1]._id }, update: { notInSchema: 2 } } } + ], + { strict: false }); + + const usersAfterUpdate = yield Promise.all([ + User.collection.findOne({ _id: users[0]._id }), + User.collection.findOne({ _id: users[1]._id }) + ]); + + assert.equal(usersAfterUpdate[0].notInSchema, 1); + assert.equal(usersAfterUpdate[1].notInSchema, 2); + }); + }); });