You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find this library really helpful in storing history of documents.
However, when there are any changes made to the document and we pass in a Javascript object, mongoose will replace the old _id properties in subdocument and replace it with new values.
Now when I change the document without making any changes to the completionCriteria array, the array remains the same but the _id property array elements change and thus this gets mentioned in History document as follows:
Ideally _id should not had changed as there are no changes in the completionCriteria array. I see a similar question here, not sure it will help. In case if you don't need _id for every element in the array, If not you can disable it as explained here.
I have not added such feature to ignore some fields, but it can be done easily by adding propertyfilter in the diff function I am using here.
I haven't tried using the propertyFilter that you discussed above, but I wrote a function that would ignore _id property in JSON.stringify step as follows:
function replacer(key, value) {
// Filtering out properties
if (key === '_id') {
return undefined;
}
return value;
}
const diff = jsondiffpatch.diff(JSON.parse(JSON.stringify(original, replacer)),
JSON.parse(JSON.stringify(updated, replacer)));
Thanks again for the help, I am closing the issue.
I find this library really helpful in storing history of documents.
However, when there are any changes made to the document and we pass in a Javascript object, mongoose will replace the old _id properties in subdocument and replace it with new values.
For example:
I have a document as follows:
Now when I change the document without making any changes to the completionCriteria array, the array remains the same but the _id property array elements change and thus this gets mentioned in History document as follows:
Is there any way to ignore the _id property because this is automatically generated by mongoose and thus can be ignored?
The text was updated successfully, but these errors were encountered: