Search code examples
javaamazon-dynamodb

DynamoDB - Remove key-value pair from Map


{
  "ExHashKey": "id_asdfqe123",
  "Data": {
    "key1": "val1",
    "key2": "val2"
  }
}

I'm trying to delete elements from the "Data" map by key. Is there a way to do this other than just retrieving the entire item, making changes, and then writing it to the DB again?

I've poked around the UpdateExpressions API a fair amount and I haven't found anything that's worked.


Solution

  • You can use the below UpdateExpression to remove the key from Map data type.

    var params = {
        TableName: "yourTableName",
        Key: {
            "ExHashKey": "id_asdfqe123"
        },
        UpdateExpression: "REMOVE Data.key1",
        ReturnValues: "ALL_NEW"
    };