I have items in a DynamoDB database table and I want to update an existing item but only a few attributes of it instead of everything. I know I can do that with for example AWS.DynamoDB.DocumentClient, using the update() function and passing UpdateExpression with the attributes I want to update in the params. I also know that I can loop through the properties of the javascript object and construct an update expression based on that but I suspect there must be an easier way to do this.
So instead of something like this (and having to implement the two fetch* functions):
const ddbDocClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: 'SomeTable',
Key: { id: someId },
UpdateExpression: fetchPropertiesOfAJavascriptObjectAndMakeAnExpressionStringOfThem(obj),
ExpressionAttributeValues: fetchValuesOfAJavascriptObjectAndMakeAValuesStringOfThem(obj)
}
ddbDocClient.update(params, (err, data) => {/* do something */});
I would like to do something like
const ddbDocClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: 'SomeTable',
Key: { id: someId },
AttributesToUpdate: obj
}
ddbDocClient.update(params, (err, data) => {/* do something */});