Skip to content

Commit

Permalink
test: repro #8778
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez committed Apr 11, 2020
1 parent ab9b22f commit 4d871c7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 4d871c7

Please sign in to comment.