Let's say you have the following blueprint object and result object.
const blueprintObj = {
propertyOne: 'One',
propertyTwo: 'Two',
propertyThree: 'Three',
propertyFour: 'Four',
}
const resultObject = {
propertyOne: 'One',
propertyThree: 'Three',
propertyFour: 'Four',
propertyFive: 'Five'
}
Notice that resultObject is missing propertyTwo but has an extra propertyFive. I've wrote a script to do this for me:
for (const data in resultObject) {
if (!blueprintObj[data]) {
delete resultObject[data];
}
}
for (const data in blueprintObj) {
if (!resultObject[data]) {
resultObject[data] = blueprintObj[data];
}
}
This works... except that resultObject is actually a document in a MongoDB database. How would I do this if blueprintObj was a regular object, and resultObject was a MongoDB document?