Reputation: 2981
I have an item in a dynamodb table that has a key of type map
. The name of the key is mykey
and the map stored in the key is:
{
name: something
address: somewhere
}
I want to add a new item to this map data. Let's say for example, color. The updated map should look like this:
{
name: something
address: somewhere
color: red
}
I am using JavaScript SDK but I'm unable to figure out how to go about this. After reading documentation, I think I need to use list_append
in updateItem
function but I am not able to figure out how.
I do not want to read data, add the new key-value, and write back. This will create a 'read before write' concurrency problem as I have multiple processes trying to update the map.
Upvotes: 1
Views: 1093
Reputation: 15955
You need to use the updateItem API. I don't have a specific example in JavaScript, but the basic idea is this:
var params = {
Key: {
KeyName: {
S: "KeyValue"
}
},
TableName: "TheTableName",
AttributeUpdates: {
color: {
Action: "ADD",
Value: {
S: "red"
}
}
}
};
client.updateItem(params, callback);
Upvotes: 2