I am trying to use the AWS Dynamodb Mapper library with Typescript to update an item in a table depending on the size of an array element (lets call it IDs) of the table.
An issue in the Github repo has been raised for this:
According to the dynamoDB documentation, there is a size operator that we can in a Condition Expression:
I haven’t seen any trace of it in the package, is it supported ?
The issue has not been addressed (the DDB documentation cited is here).
I would like the condition to be something like size(IDs) > 12
, but FunctionExpression
doesn’t seem to support this.
How can I use this mapper library to implement a size
condition?
2
Answers
It looks like this is not possible using mapper, but it is possible to use the
marshallConditionExpression
function in mapper to create a serialized update condition, then manually append the size condition. This can then be used with the ddb client directly to update the item. So mapper doesn't support it, but supports hacking a solution together.I think as you probably might know the solution but hoping for something better.
You could, when inserting data into this array you also calculated the size, save/update this as an attribute, then you can use in an index for quick searching as a work around for this not yet being in the library.
You could also make a pull request ( ;