From f4766412ddfcd01027c801bd5139c1298e7b3888 Mon Sep 17 00:00:00 2001 From: Mahdi Amiri Date: Wed, 21 Feb 2024 15:44:54 +0330 Subject: [PATCH] Prevent error in case of empty updateFields --- lib/mongoose-field-encryption.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mongoose-field-encryption.js b/lib/mongoose-field-encryption.js index f6b1847..d3783f1 100644 --- a/lib/mongoose-field-encryption.js +++ b/lib/mongoose-field-encryption.js @@ -194,6 +194,7 @@ const fieldEncryption = function (schema, options) { function updateHook(_next) { const next = getCompatitibleNextFunc(_next); + if (this._update === undefined) next(); for (const field of fieldsToEncrypt) { const encryptedFieldName = encryptedFieldNamePrefix + field; this._update.$set = this._update.$set || {};