-1

I want to add a item in a attribute which is a list, if that item does not already exists in the list of that attribute. Is there any way I can write the same in UPDATEEXPRESSION?

I need below like result the order of item does not matter:

[1,2,3,4]+[5]=[1,2,3,4,5]
[1,2,3,4]+[3]=[1,2,3,4]
[1,2,3,4]+[3,5]=[1,2,3,4,5]
  • what have done so far to solve the issue?, supply a minimal example of the code that isn't working – Nath Sep 29 '22 at 08:47
  • Potential solution here: https://stackoverflow.com/questions/57030981/add-to-list-only-if-string-doesnt-already-exist-in-dynamodb-table – Bert Blommers Sep 29 '22 at 14:24

1 Answers1

0

DynamoDB supports a few types of Attribute Values including sets.

You can use the three sets (Binary Set (BS), Number Set (NS), or String Set (SS)) to safely ADD an item. The updated item will be the union set of the existing set and the new one:

If the existing data type is a set and if Value is also a set, then Value is added to the existing set. For example, if the attribute value is the set [1,2], and the ADD action specified [3], then the final attribute value is [1,2,3]. An error occurs if an ADD action is specified for a set attribute and the attribute type specified does not match the existing set type.

Guy
  • 12,388
  • 3
  • 45
  • 67