I have been working on tracking changes in a mongoDB record that I send through a GET request and then update with a PUT request.
When the PUT request is received, I retrieve the existing document before updating it, and then compare it with the updated record. I exclude certain items like "updated_at" and a few other fields during the comparison process.
Here is my code snippet:
However, I am encountering an issue when calling the recursive comparison function. For the same array being checked, it always returns as modified, even if it isn't. Any suggestions or feedback?
You can find the complete JavaScript code on this jsfiddle: https://jsfiddle.net/vrw2ghja/8/
The objects _existingObj and _updatedObj are two different Objects, whereas, _cloneOf_existingObj is a clone of _existingObj
const compare = (obj1, obj2) => {
// Implementation of the comparison logic
};
const check = (a, b) => {
console.log("==========================");
console.log(`Are objects ${a} and ${b} modified? ${compare(a, b)}`);
}
// Sample object instances
var _existingObj={ ... };
var _updatedObj={ ... };
var _cloneOf_existingObj={ ... };
check(_existingObj, _updatedObj);
check(_existingObj,_cloneOf_existingObj);