4ossiblellc / dynamodb-update-expression

A small library providing the solution to return the DynamoDB update expression.
MIT License
25 stars 15 forks source link

Removing one element from an array causes an empty SET #6

Closed bmmathe closed 7 years ago

bmmathe commented 7 years ago

When trying to issue a remove expression when only one item is specified to be removed from a list an empty SET expression is generated.

var removeItem = { "Options": [ { Votes: '0', Name: 'Wheel of Time' } ] }

{ UpdateExpression: 'SET REMOVE #Options', ExpressionAttributeNames: { '#Options': 'Options' }, TableName: 'Polls', Key: { PollId: 'hTB5MG2e', Created: '2016-11-06T03:19:12.788Z' }, ReturnValues: 'ALL_NEW' }

Error JSON: { "message": "Invalid UpdateExpression: Syntax error; token: \"REMOVE\", near: \"SET REMOVE #Options\"", "code": "ValidationException", "time": "2016-11-06T16:04:30.560Z", "requestId": "5f92a91a-f43e-4e08-a556-fee6c54e9dab", "statusCode": 400, "retryable": false, "retryDelay": 0 }

One option could be to find the element index in the array you want to remove and issue a REMOVE expression like: REMOVE Options[2]

4ossiblellc commented 7 years ago

Thanks for the feedback. Yes, you are right. The current version does not handle array very well. We will work on this in these few days. Please stay tuned.

4ossiblellc commented 7 years ago

@jazarja made a fix. I will release that soon after running some test.

4ossiblellc commented 7 years ago

@bmmathe can you please download the 0.1.16 version and see if it fixes your issue? Please let me know then I will close this ticket.

4ossiblellc commented 7 years ago

@bmmathe does the fix work for you?

4ossiblellc commented 7 years ago

Close this ticket as no response from author.