我想用以下逻辑实现DynamoDB Scan:
扫描 - >过滤(布尔值为true或false) - >限制(用于分页)
但是,我只能用这个逻辑实现Scan:
扫描 - >限制(用于分页) - >过滤(布尔值为true或false)
我怎样才能做到这一点?
下面是我编写的实现第二个扫描逻辑的示例:
var parameters = {
TableName: this.tableName,
Limit: queryStatement.limit
};
if ('role' in queryStatement) {
parameters.FilterExpression = '#role = :role';
parameters.ExpressionAttributeNames = {
'#role': 'role'
};
parameters.ExpressionAttributeValues = {
':role': queryStatement.role
};
}
if ('startKey' in queryStatement) {
parameters.ExclusiveStartKey = { id: queryStatement.startKey};
}
this.documentClient.scan(parameters, (errorResult, result) => {
if (errorResult) {
errorResult._status = 500;
return reject(errorResult);
}
return resolve(result);
});
Run Code Online (Sandbox Code Playgroud)
这个代码就像第二个一样.
扫描 - >限制 - …
我想扫描我的 Dynamo db 表并对其应用分页。在我的请求中,我想从我想要开始分页的地方发送号码。说,例如,我发送的请求的 start = 3 和 limit = 10,其中 start 是我希望扫描从表中的第三个项目开始,而限制最多为 10 个项目。但是我可以使用 .withLimit() 方法来实现限制(我使用的是 java)。我遵循了这个aws 文档。以下是我想要实现的代码:
<Map<String, AttributeValue>> mapList = new ArrayList<>();
AmazonDynamoDB client =AmazonDynamoDBClientBuilder.standard().build();
Gson gson = new GsonBuilder().serializeNulls().create();
Map<String, AttributeValue> expressionAttributeValues = new
HashMap<String,AttributeValue>();
expressionAttributeValues.put(":name",
newAttributeValue().withS(name));
List<ResponseDomain> domainList = new ArrayList<>();
ResponseDomain responseDomain = null;
//lastKeyEvaluated = start
Map<String, AttributeValue> lastKeyEvaluated = null;
do {
ScanRequest scanRequest = new
ScanRequest().withTableName(STUDENT_TABLE)
.withProjectionExpression("studentId, studentName")
.withFilterExpression("begins_with(studentName, :name)")
.withExpressionAttributeValues(expressionAttributeValues).
withExclusiveStartKey(lastKeyEvaluated);
ScanResult result = client.scan(scanRequest);
for (Map<String, AttributeValue> …Run Code Online (Sandbox Code Playgroud) database pagination json amazon-web-services amazon-dynamodb