問題描述
我實際上是不正確的.當我打算查詢解釋我的錯誤的索引時,我正在查詢表.不過 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.
這篇關于使用 java sdk 從具有哈希范圍模式的給定哈希鍵查詢 DynamoDB 中的所有項目的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!