使用 java sdk 从具有哈希范围模式的给定哈希键查询 DynamoDB 中的所有项目
我实际上是不正确的.当我打算查询解释我的错误的索引时,我正在查询表.不过 Vikdor 的解决方案是有效的.
I was actually incorrect. I was querying the table when I meant to query an index which explains my error. Vikdor's solution is a valid one though.
原文:我在 DynamoDB 中有一个带有哈希范围键模式的表.我需要能够获取与特定哈希键关联的所有项目,但它似乎需要一个范围键条件.我的问题是我想要每个范围键,但没有通配符选项.截至目前,我的范围键是一个字符串,我能想到的唯一方法是查询所有大于或等于我可以使用的最小 ascii 字符的范围键,因为文档说它是根据 ascii 字符值排序的.
ORIGINAL: I have a table with a Hash-Range key schema in DynamoDB. I need to be able to get all items associated with a specific hash key but it seems to require a range key condition. My issue is I want EVERY range key but there is no wildcard option. As of right now my range key is a string and the only way I could think to do this is by querying all range keys greater or equal to the smallest ascii characters I can use since the documentation says it sorts based on ascii character values.
我研究过扫描,但似乎只会读取整个表格,这不是一个选项.
I looked into scanning but it appears that simply will read the entire table which is NOT an option.
有没有更好的方法来查询哈希键的所有值,或者任何人都可以确认使用带有 ascii 字符的方法是否有效?
Is there any better way to query for all values of a hash key or can anyone confirm that using the method with the ascii character will work?
推荐答案
但它似乎需要一个范围键条件.
but it seems to require a range key condition.
这听起来不是真的.
我使用 DynamoDBMapper 并使用 DynamoDBQueryExpression 查询具有给定 HashKey 的所有记录,如下所示:
I use DynamoDBMapper and use DynamoDBQueryExpression to query all the records with a given HashKey as follows:
DynamoDBQueryExpression<DomainObject> query =
new DynamoDBQueryExpression<DomainObject>();
DomainObject hashKeyValues = new DomainObject();
hashKeyValues.setHashKey(hashKeyValue);
query.setHashKeyValues(hashKeyValues);
// getMapper() returns a DynamoDBMapper object with the appropriate
// AmazonDynamoDBClient object.
List<DomainObject> results = getMapper().query(query);
HTH.
相关文章