I have many objects with unique identifiers. Each object can have several labels associated with it, for example:
123: ['a', 'hello'] 456: ['dsajdaskldjs'] 789: (no labels associated yet)
I do not plan to store all objects in DynamoDB, only these label sets. Therefore, it would be advisable to add such shortcuts:
- find the entry with (id = needed_id)
- if there is one and it has a set called
label_set , add a label to this set - if there is no record with this identifier, or if the existing record does not have an attribute named
label_set , create a record and attribute and initialize the attribute using a set of labels
If I used sets of numbers, I could only use the ADD command of the UPDATE command. This command does exactly what I described. However, this does not work with row sets:
If the item does not match the specified primary key:
ADD- Creates an element with the provided primary key and number (or set of numbers) for the attribute value. Not valid for string type.
so I have to use the PUT operation with Expected set to {"label_set":{"Exists":false}} , and then (if it fails) using the ADD operation. These are two operations, and this sucks (since you pay for the operation, the cost of this will be 2 times more than they can be).
These restrictions seem very strange to me. Why doesn't something that works with sets of numbers not work with sets of strings? Maybe I'm doing something wrong.
Using many records, such as (123, 'a'), (123, 'hello') instead of a single record per object with a set, is not a solution: I want to get all the values from the set at once, without any scans.
source share