3

For example, I have a table with userID as hash key. The same table contains commentID as range key. I want to find all entries related to a specific userID. Using java SDK, what is the most efficient way to retrieve all items that has a particular hash key.

SOLUTION
Here's how I did it:

QuerySpec spec = new QuerySpec()
                .withKeyConditionExpression("userID = :v_id")
                .withValueMap(new ValueMap()
                    .withString(":v_id", user.getId()));

ItemCollection<QueryOutcome> items = table.query(spec);

Iterator<Item> iterator = items.iterator();
Item item = null;
while (iterator.hasNext()) {
      item = iterator.next();
      System.out.println(item.toJSONPretty());
}
1
  • Just use query or getItem to get all the values of your hash key..! Commented Mar 30, 2016 at 12:49

1 Answer 1

1

The way to "scan" a hash key in DynamoDB is called Query. Use this API either with the DynamoDBMapper or Document API to fetch all items for a specific hash.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.