猿问

使用 Java 查询 DynamoDB

如何仅使用主键查询/扫描 DynamoDB 表?我能够从表中返回结果的唯一方法是下面的代码,我在其中设置了主键Id并Condition使用排序键添加了 a 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());


慕村9548890
浏览 279回答 1
1回答

qq_遁去的一_1

弄清楚了。您不必包括withRangeKeyCondition:DynamoDataObject data = new DynamoDataObject();data.setId(userId);DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression()&nbsp; &nbsp; .withHashKeyValues(data)&nbsp; &nbsp; .withConsistentRead(false);PaginatedList<DynamoDataObject > result = AWSProvider.getInstance().getDynamoDBMapper().query(DynamoDataObject.class, queryExpression);Log.d(TAG, "PaginatedList length: " + result.size());
随时随地看视频慕课网APP

相关分类

Java
我要回答