amazon-web-services - DynamoDB : Query for range key in a set of non-sequential range keys

标签 amazon-web-services amazon-dynamodb

我有一个使用哈希键和排序(范围)键的表。我的范围键是 uuid。我有一个案例,我有一组任意范围键,我想使用 DynamoDBMapper 查询数据库。它们绝不是连续的,不幸的是,出于我的目的,它们不可能是连续的,因此我无法查询一系列键(即键在 a 和 b 之间)。有没有办法让查询条件搜索一组潜在值中的范围键?本质上是一个 sql WHERE 条件,例如:rangeKey IN (val1, val2, ...);

根据 DynamoDBQueryExpression 的文档使用 setKeyConditionExpression 或 setRangeKeyConditions 似乎不可能实现这一点。有什么有效的方法可以做到这一点吗?或者我最好的选择是迭代我的一组潜在值并使用 load 方法从数据库中单独检索它们?

最佳答案

根据文档 hereQuery 不支持

IN 操作:

The sort key condition must use one of the following comparison operators:

  • a = b — true if the attribute a is equal to the value b
  • a < b — true if a is less than b
  • a <= b — true if a is less than or equal to b
  • a > b — true if a is greater than b
  • a >= b — true if a is greater than or equal to b
  • a BETWEEN b AND c — true if a is greater than or equal to b, and less than or equal to c.

The following function is also supported:

begins_with (a, substr)— true if the value of attribute a begins with a particular substring.

此外,您始终需要精确的哈希 key 才能执行查询。如果这适合您的使用案例,您应该查询 DynamoDB 并在应用程序层应用IN 过滤器。

如果您没有确切的哈希 key ,请执行Scan,它确实具有用于过滤的IN操作。文档 here .

关于amazon-web-services - DynamoDB : Query for range key in a set of non-sequential range keys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42170444/

相关文章:

python - 在 Airflow2.0 中自动日志清理 dag 不起作用

php - 502 高负载下使用 PHP-FPM 的 nginx 网关错误

amazon-dynamodb - Dynamodb 本地 - 连接被拒绝

ios - 亚马逊的开发人员身份验证

visual-studio - Elastic beanstalk 不显示 Web 应用程序

python - AWS Lambda 找不到模块 Python

java - 将 RSA pem key 字符串转换为 der byte[]

java - dynamodb 我如何模拟映射器?

ios - "message": "Internal server error" issue with Lambda/API Gateway and iOS

amazon-dynamodb - 在 DynamoDB 中建模关系数据(嵌套关系)