如何仅使用主键查询/扫描DynamoDB表?我能够从表中返回结果的唯一方法是下面的代码,其中设置主键Id
并使用排序键Condition
添加Date
。
是否可以在不提供RangeKeyCondition
的情况下查询表?
DynamoDataObject data = new DynamoDataObject();
data.setId(userId);
Condition rangeKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.BEGINS_WITH)
.withAttributeValueList(new AttributeValue().withS("2018"));
DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression()
.withHashKeyValues(data)
.withRangeKeyCondition("Date", rangeKeyCondition)
.withConsistentRead(false);
PaginatedList<DynamoDataObject > result = AWSProvider.getInstance().getDynamoDBMapper().query(DynamoDataObject.class, queryExpression);
Log.d(TAG, "PaginatedList length: " + result.size());
答案 0 :(得分:0)
弄清楚了。您不必包括withRangeKeyCondition
:
DynamoDataObject data = new DynamoDataObject();
data.setId(userId);
DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression()
.withHashKeyValues(data)
.withConsistentRead(false);
PaginatedList<DynamoDataObject > result = AWSProvider.getInstance().getDynamoDBMapper().query(DynamoDataObject.class, queryExpression);
Log.d(TAG, "PaginatedList length: " + result.size());