Replies: 2 comments 1 reply
-
Looks like something I would write to check if 2 objects are different. Maybe you can also only do it when certain fields change you care about. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi Matthijs, thank you for your reply. In the end I did the following: export default function hasChanged(doc, previousDoc) {
return !areObjEqual(doc, previousDoc, { ignoreKeys: ['__v', 'updatedAt', '_id'] })
}
function areObjEqual(a, b, { ignoreKeys = [] } = {}) {
let aMod = Object.entries(a).filter(([key]) => !ignoreKeys.includes(key)).sort()
let bMod = Object.entries(b).filter(([key]) => !ignoreKeys.includes(key)).sort()
return JSON.stringify(aMod) == JSON.stringify(bMod)
} This helps me to prevent triggering unnecessary fs operations. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi community,
I'd like to check if a collection has really changed before I do filesystem operations.
Does somebody have a recommended approach?
I tried the following but it always returns that the collection has changed...
Beta Was this translation helpful? Give feedback.
All reactions