1

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.

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.