我有一个使用哈希键和排序(范围)键的表。我的范围键是 uuid。我有一个案例,我有一组任意范围键,我想使用 DynamoDBMapper 查询数据库。它们绝不是连续的,不幸的是,出于我的目的,它们不可能是连续的,因此我无法查询一系列键(即键在 a 和 b 之间)。有没有办法让查询条件搜索一组潜在值中的范围键?本质上是一个 sql WHERE 条件,例如:rangeKey IN (val1, val2, ...);
根据 DynamoDBQueryExpression 的文档使用 setKeyConditionExpression 或 setRangeKeyConditions 似乎不可能实现这一点。有什么有效的方法可以做到这一点吗?或者我最好的选择是迭代我的一组潜在值并使用 load 方法从数据库中单独检索它们?
最佳答案
根据文档 here,Query
不支持
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/