Last active
September 20, 2024 09:43
-
-
Save cfsghost/1a33f71386589398787d2e5c8fd82580 to your computer and use it in GitHub Desktop.
Column updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mergeUpdates(data) { | |
let output = {}; | |
Object.entries(data).forEach(function(entry) { | |
let key = entry[0]; | |
let value = entry[1]; | |
if (key.startsWith(fieldName + '.')) { | |
let column = key.split('.')[1]; | |
output[column] = value; | |
return | |
} | |
output[key] = value; | |
}) | |
return; | |
} | |
return mergeUpdates(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getUpdates(fieldName) { | |
let updates = {}; | |
Object.entries(source).forEach(function(entry) { | |
let key = entry[0]; | |
let value = entry[1]; | |
if (key.startsWith(fieldName + '.')) { | |
let column = key.split('.')[1]; | |
updates[column] = value; | |
} | |
}); | |
return updates; | |
} | |
return { | |
"_id": source._id, | |
"a": source.a, | |
"map_col": Object.assign({}, source.map_col, getUpdates('map_col')) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMapValue(fieldName) { | |
let updates = source[fieldName] || {}; | |
Object.entries(source).forEach(function(entry) { | |
let key = entry[0]; | |
let value = entry[1]; | |
if (key.startsWith(fieldName + '.')) { | |
let column = key.split('.')[1]; | |
updates[column] = value; | |
} | |
}); | |
return updates; | |
} | |
return { | |
"_id": source._id, | |
"a": source.a, | |
"map_col": getMapValue('map_col') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment