From 6c1dcb28cc6eb528a3710f64fe3cc95ea7e628ff Mon Sep 17 00:00:00 2001 From: Hafez Date: Wed, 13 Nov 2019 15:50:42 +0200 Subject: [PATCH] Fixes #8331 --- lib/helpers/model/castBulkWrite.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/helpers/model/castBulkWrite.js b/lib/helpers/model/castBulkWrite.js index f4e15648979..f724afb0b31 100644 --- a/lib/helpers/model/castBulkWrite.js +++ b/lib/helpers/model/castBulkWrite.js @@ -34,6 +34,9 @@ module.exports = function castBulkWrite(model, op, options) { op = op['updateOne']; return (callback) => { try { + if (!op['filter']) throw new Error('Must provide a filter object.'); + if (!op['update']) throw new Error('Must provide an update object.'); + op['filter'] = cast(model.schema, op['filter']); op['update'] = castUpdate(model.schema, op['update'], { strict: model.schema.options.strict, @@ -61,6 +64,9 @@ module.exports = function castBulkWrite(model, op, options) { op = op['updateMany']; return (callback) => { try { + if (!op['filter']) throw new Error('Must provide a filter object.'); + if (!op['update']) throw new Error('Must provide an update object.'); + op['filter'] = cast(model.schema, op['filter']); op['update'] = castUpdate(model.schema, op['update'], { strict: model.schema.options.strict,