【问题标题】:Removing a List Item from DynamoDb从 DynamoDb 中删除列表项
【发布时间】:2020-12-14 03:11:19
【问题描述】:

需要使用其索引从 React 应用程序中的 DynamoDb 数据库中删除列表项。

以示例为例 https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Js.03.html , 更新项目(有条件)

删除项目的更新表达式是

UpdateExpression: "remove info.actors[0]",

当索引值是函数的参数时,更新表达式是什么?

【问题讨论】:

  • 如果您只想使用参数而不是硬编码的零,是否有理由不能只使用索引构建字符串?例如。 "删除 info.actors[" + index + "]"

标签: javascript amazon-dynamodb


【解决方案1】:

这样做的唯一方法是构建UpdateExpression 字符串,其中包含适当的数字。正如 LazyElephant 在评论中建议的那样:"Remove info.actors[" + index + "]"

您可能认为也应该可以写成remove info.actors[:i],其中:iExpressionAttributeValues 中定义。但不幸的是,这不起作用。 DynamoDB 将其作为语法错误拒绝。我不能说我明白为什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-20
    • 1970-01-01
    • 2013-04-04
    相关资源
    最近更新 更多