I would like to implement a DynamoDB Scan with the following logic:
Scanning -> Filtering(boolean true or false) -> Limiting(for pagination)
However, I have only been able to implement a Scan with this logic:
Scanning -> Limiting(for pagination) -> Filtering(boolean true or false)
How can I achieve this?
Below is an example I have written that implements the second Scan logic:
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);
});
This codes works like second one.
Scanning -> Limiting -> Filtering