Remove nested attribute in dynamodb

Viewed 6215

Let's say I have this item in DynamoDB:

{
  "customerId": "customer_001",
  "customerName": "itsme",
  "address": {
    "city": "Frankfurt",
    "country": "Germany",
    "street1": "c/o Company xxx",
    "street2": "Europe",
    "street3": "PO Box 406",
    "zip": "12345"
  }
}

I need to remove the nested attribute address.street3 from the item. How I can accomplish this?

Here is my code below; it works perfectly to remove non-nested attributes (for example, customerName), but if I try to use this in nested attributes (like address.street3), it silently fails.

const params = {
    TableName: customerTable,
    Key: {
        customerId: customerId,
    },
    AttributeUpdates: {
        'address.street3':
        {
            Action: 'DELETE'
        }
    }
};

dynamoDb.update(params, function (err, data) {
    if (err) {
        console.error("Unable to update customer. Error JSON:", JSON.stringify(err, null, 2));
    }
    else {
        console.log("UpdateCustomer succeeded:", JSON.stringify(data.Attributes));
        responseHelper.ResponseHelper.success(JSON.stringify(data.Attributes), 200, callback);
    }
});

What can I remove the nested attribute address.street3?

1 Answers
Related