Skip to content

Instantly share code, notes, and snippets.

@alex-samborskiy
Forked from organizm/remove.attribute.js
Last active June 5, 2019 16:05
Show Gist options
  • Select an option

  • Save alex-samborskiy/c3b79aeaa6907c097e39cfc30b414f47 to your computer and use it in GitHub Desktop.

Select an option

Save alex-samborskiy/c3b79aeaa6907c097e39cfc30b414f47 to your computer and use it in GitHub Desktop.
[Remove nested attribute in DynamoDB]#DynamoDB
const docClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName : "customer",
Key : {
"customerId": "customer_001"
},
UpdateExpression : "REMOVE address.street3",
ReturnValues : "UPDATED_NEW"
};
console.log("Updating the item...");
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data));
}
});
//Each nested property should be used through ExpressionAttributeNames. Like: #obj.#propL1.#propL2......
//In case if #ptoperty not exist in #object it will be created. But if #object not exist it will be an error
const ddb = new DynamoDB.DocumentClient({convertEmptyValues: true});
ddb
.update({
TableName: TABLE_NAME,
Key: {
primary_key: primaryKey,
sort_key: sortKey
},
UpdateExpression: 'set #object.#ptoperty = :value',
ExpressionAttributeNames: {
'#object': 'someObject',
'#key': someProperty
},
ExpressionAttributeValues: {
':value': value
}
})
.promise();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment