blucaroni
blucaroni

Reputation: 63

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.

Upvotes: 6

Views: 7717

Answers (1)

notionquest
notionquest

Reputation: 39226

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"
};

Upvotes: 19

Related Questions