0

i have one AmazonDynamoDB whose hashKey is: "userId" and rangeKey is: "timestamp".

I am writing one query for fetching up all records related to particular userId.

String keyConditionExpression = "userId = :userId";
HashMap<String, AttributeValue> attributeValuesMap = new HashMap<>();
attributeValuesMap.put(":userId", new AttributeValue().withS("someId"));

DynamoDBQueryExpression<MyTableItem> queryExpression =
                new DynamoDBQueryExpression<MyTableItem>()
                .withKeyConditionExpression(keyConditionExpression)
                .withExpressionAttributeValues(attributeValuesMap)
                .withConsistentRead(false);

dynamoDBMapper.queryPage(MyTableItem.class, queryExpression);

this query operation is failing, but not able to see, why it's failing. As given here, this should come under query criteria.

Any help would be really appreciated. Thanks.

Shivanshu
  • 784
  • 1
  • 5
  • 20

1 Answers1

0

I have tested the code and it runs as expected, returning the correct results. Is userId your tables Partition Key?

Can you share which error you are getting, that will help to recommend a solution.

    DynamoDBMapper mapper = new DynamoDBMapper(client);

    String keyConditionExpression = "userId = :userId";
    HashMap<String, AttributeValue> attributeValuesMap = new HashMap<>();
    attributeValuesMap.put(":userId", new AttributeValue().withS("leeroy"));

    DynamoDBQueryExpression<BillingDashboardRecord> queryExpression =
            new DynamoDBQueryExpression<BillingDashboardRecord>()
                    .withKeyConditionExpression(keyConditionExpression)
                    .withExpressionAttributeValues(attributeValuesMap)
                    .withConsistentRead(false);

    try{
        mapper.queryPage(BillingDashboardRecord.class, queryExpression);
    }catch (Exception e){
        System.out.println(e.getMessage());
    }
Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31