简体   繁体   English

映射 dynamodb 查询结果

[英]Mapping a dynamodb query result

I have a table with a composite key;我有一个带有复合键的表; there is both a partition and a sort key.有一个分区和一个排序键。 I know that the java sdk allows me to query by just the partition key.我知道 java sdk 允许我仅通过分区键进行查询。 However, if I do this then the docs say I will get this iterator back ItemCollection<QueryOutcome> .但是,如果我这样做,那么文档说我将把这个迭代器取回ItemCollection<QueryOutcome> This means for me to work with this data, I will have to iterate over the entire collection in order to fulfill my needs.这意味着我要处理这些数据,我将不得不遍历整个集合以满足我的需求。

It would be easier if I was able to get back a Map<T, V> type where the key here would be the sort key.如果我能够取回Map<T, V>类型,这里的键将是排序键,那就更容易了。 That way, I can quickly find rows for a particular sort key.这样,我可以快速找到特定排序键的行。 Is this possible?这可能吗? I would rather not iterate over the collection just to find certain items with a certain sort key value.我宁愿不迭代集合只是为了找到具有特定排序键值的特定项目。

If you just want an item with a certain sort key, that's a get item.如果您只想要一个具有特定排序键的项目,那就是一个获取项目。 Don't do a Query.不要做查询。

You may be confused by DynamoDB's use of the word Query.您可能会对 DynamoDB 使用“查询”一词感到困惑。 That's not the only way to query the database.这不是查询数据库的唯一方法。 It's one way to query which happens to have the name Query.这是一种查询恰好名称为 Query 的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM