【发布时间】:2017-04-20 16:20:33
【问题描述】:
我有一个名为“product”的 DynamoDB 表,在“userId”上有一个全局二级索引。主键在“id”上。 我正在尝试在“userID”GSI 上使用“withExclusiveStartKey”实现分页查询。 但是,当我传递一个有效的 lastId 时,我得到以下异常:
独占开始键的大小必须与表的键模式相同 (服务:AmazonDynamoDBv2;状态代码:400;错误代码: 验证异常;请求编号: 822db97e-04a3-4c36-8c72-6008e2693679)
我在这里做错了什么?
public QueryResultPage<Product> findPaged(String userId,int limit,String lastId) {
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDb);
Map<String, AttributeValue> vals = new HashMap<>();
vals.put(":valUserId", new AttributeValue().withS(userId));
DynamoDBQueryExpression<Product> queryExp = new DynamoDBQueryExpression<Product>()
.withKeyConditionExpression("userId = :valUserId")
.withIndexName(ModelConsts.TBL_PRODUCT_GSI_USERID)
.withExpressionAttributeValues(vals)
.withScanIndexForward(false)
.withConsistentRead(false)
.withLimit(limit);
if (lastId != null) {//paging
Map<String, AttributeValue> exclusiveStartKey = new HashMap<String, AttributeValue>();
exclusiveStartKey.put("id", new AttributeValue().withS(lastId));
queryExp = queryExp.withExclusiveStartKey(exclusiveStartKey);
}
QueryResultPage<Product> result = mapper.queryPage(Product.class, queryExp);
return result;
}
【问题讨论】:
标签: pagination amazon amazon-dynamodb