Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 815
blucaroni Avatar asked Aug 26 '26 02:08

blucaroni


1 Answers

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"
};
like image 120
notionquest Avatar answered Aug 28 '26 16:08

notionquest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!