I have a list of maps as one field of a DynamoDB table. How can I update a specific element (or, rather element field ?) Trying something like
rc = table.update_item(Key={ 'username' : user },
UpdateExpression="set list[:i].field = :nd",
ExpressionAttributeValues={
':i' : itemnum,
':nd': data,
},
ReturnValues="UPDATED_NEW"
);
But I am getting an error:
Invalid UpdateExpression: Syntax error; token: ":i", near: "[:i]"
Any ideas how can I reference list element with variable number. Thanks.
The only way to update multiple items at the same time is use TransactionWrite operation provided by DynamoDB. But it comes with a limitation (25 at most for example). So keep in mind with that, you probable should do some limitation in your application as well.
Can we update the sort key in DynamoDB? No, you can not update the sort key after the table is provisioned. However, you can create a new table and put the existing data in the newly created table, and delete the old table.
The putItem function creates an entirely new item or replaces an existing item from a DynamoDB table. So, unlike the updateItem function, you can not use the putItem function to update existing items. The behavior of the putItem function is determined by the primary key you provide.
A bulk (batch) update refers to updating multiple rows belonging to a single table. However, DynamoDB does not provide the support for this.
Use a literal instead:
rc = table.update_item(Key={ 'username' : user },
UpdateExpression="set list[" + itemnum + "].field = :nd",
ExpressionAttributeValues={
':nd': data,
},
ReturnValues="UPDATED_NEW"
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With