Kiwi breeder
Kiwi breeder

Reputation: 627

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. However, if I do this then the docs say I will get this iterator back 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. 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.

Upvotes: 1

Views: 562

Answers (1)

hunterhacker
hunterhacker

Reputation: 7152

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. That’s not the only way to query the database. It’s one way to query which happens to have the name Query.

Upvotes: 1

Related Questions