Skip to content

Commit

Permalink
Fix(mongoose-audit): added query clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 authored Mar 10, 2024
1 parent 305c54f commit 86200f6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/mongoose-audit/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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)
Expand Down

0 comments on commit 86200f6

Please sign in to comment.