From 86200f60d0d6b5e16a2839ea001a17423c7a5441 Mon Sep 17 00:00:00 2001 From: Akalanka Perera Date: Sun, 10 Mar 2024 18:24:29 +0000 Subject: [PATCH] Fix(mongoose-audit): added query clone --- plugins/mongoose-audit/src/plugin.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mongoose-audit/src/plugin.js b/plugins/mongoose-audit/src/plugin.js index 202c0b7..3cbb48a 100644 --- a/plugins/mongoose-audit/src/plugin.js +++ b/plugins/mongoose-audit/src/plugin.js @@ -84,6 +84,7 @@ const addAuditLog = async (currentObject) => { const addUpdate = async (query, multi) => { const updated = flattenObject(query._update); let counter = 0; + if (query.clone) query = query.clone() const originalDocs = await query.find(query._conditions).lean(true) const promises = originalDocs.map((original) => { if (!multi && counter++) { @@ -110,6 +111,7 @@ const addDelete = async (currentObject, options) => { }; const addFindAndDelete = async (query) => { + if (query.clone) query = query.clone() const originalDocs = await query.find().lean(true) const promises = originalDocs.map((original) => { return addDelete(original, query.options)