-
-
Save alex-samborskiy/c3b79aeaa6907c097e39cfc30b414f47 to your computer and use it in GitHub Desktop.
[Remove nested attribute in DynamoDB]#DynamoDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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