I need make a scan with limit and a condition on DynamoDB.
The docs says:
In a response, DynamoDB returns all the matching results within the scope of the Limit value. For example, if you issue a Query or a Scan request with a Limit value of 6 and without a filter expression, DynamoDB returns the first six items in the table that match the specified key conditions in the request (or just the first six items in the case of a Scan with no filter). If you also supply a FilterExpression value, DynamoDB will return the items in the first six that also match the filter requirements (the number of results returned will be less than or equal to 6).
The code (NODEJS):
var params = {
ExpressionAttributeNames: {"#user": "User"},
ExpressionAttributeValues: {":user": parseInt(user.id)},
FilterExpression: "#user = :user and attribute_not_exists(Removed)",
Limit: 2,
TableName: "XXXX"
};
DynamoDB.scan(params, function(err, data) {
if (err) {
dataToSend.message = "Unable to query. Error: " + err.message;
} else if (data.Items.length == 0) {
dataToSend.message = "No results were found.";
} else {
dataToSend.data = data.Items;
console.log(dataToSend);
}
});
Table XXXX definitions:
- Primary partition key: User (Number)
- Primary sort key: Identifier (String)
- INDEX:
- Index Name: RemovedIndex
- Type: GSI
- Partition key: Removed (Number)
- Sort key: -
- Attributes: ALL
In code above, if I remove the Limit
parameter, DynamoDB will return the items that match the filter requirements. So, the conditions are ok. But when I scan with Limit
parameter, the result is empty.
The XXXX table, has 5 items. Only the 2 firsts have the Removed
attribute. When I scan without Limit
parameter, DynamoDB returns the 3 items without Removed
attribute.
What i'm doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…