英文:
How to create a size condition useing AWS dynamodb-mapper-js
问题
我尝试使用AWS DynamoDB Mapper库与TypeScript一起根据表中数组元素的大小(我们称之为IDs)更新项目。
根据DynamoDB文档,我们可以在条件表达式中使用一个size运算符:
我没有在包中看到任何关于它的迹象,它是否受支持?
这个问题尚未得到解决(DDB文档引用在此处)。
我希望条件可以是类似size(IDs) > 12
的内容,但FunctionExpression
似乎不支持这样的条件。
我该如何使用这个Mapper库来实现一个size
条件?
英文:
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?
答案1
得分: 1
我认为你可能已经知道解决方案,但希望有更好的方法。
当向这个数组插入数据时,你还可以计算大小,并将其保存/更新为一个属性,然后你可以将其用作快速搜索的索引,作为库中尚未实现的一种解决方法。
你还可以提交一个拉取请求(;
英文:
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 ( ;
答案2
得分: 0
看起来使用“mapper”不可能实现这一点,但可以使用“marshallConditionExpression”函数在“mapper”中创建一个序列化的更新条件,然后手动附加大小条件。然后可以直接使用DynamoDB客户端更新项目。因此,“mapper”不支持它,但支持拼凑一个解决方案。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论