0
votes

Need to remove a list item from a DynamoDb database in a react app using its index.

Going by the example in https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Js.03.html , Update an Item (Conditionally)

The update expression for removing an item is

UpdateExpression: "remove info.actors[0]",

What is the update expression when the index value is a parameter to the function?

1
If you just want to use the parameter instead of the hard coded zero, is there a reason you can't just build the string with the index? eg. "Remove info.actors[" + index + "]" - LazyElephant

1 Answers

1
votes

The only way to do this is to just build the UpdateExpression string with the appropriate number in it. As LazyElephant suggested in a comment: "Remove info.actors[" + index + "]".

You might think that it should also be possible to write remove info.actors[:i] where :i is defined in ExpressionAttributeValues. But unfortunately, this doesn't work. DynamoDB refuses it as a syntax error. I can't say I understand why.