- Newest
- Most votes
- Most comments
What's happening here is that you set a FilterExpression and a Limit. What happens now is that DynamoDB reads 5 items as that is your Limit and then applies your filter to those 5 items but none match the expression so you get an empty response.
Changing the date is simply changing the 5 items read and it's just luck that they match your filter. The same goes for changing the scan direction, you're just changing the first 5 items.
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
A single Query operation will read up to the maximum number of items set (if using the Limit parameter) or a maximum of 1 MB of data and then apply any filtering to the results using FilterExpression. If LastEvaluatedKey is present in the response, you will need to paginate the result set. For more information, see Paginating the Results in the Amazon DynamoDB Developer Guide.
Hi there please refer to the following doc for guidance https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.ReadData.Query.html
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 3 years ago
Why is it that it reads first 5 items and then filters and not the other way around? Do we have some workaround for this scenario?
This is how it works, as outlined in the documentation and edited my answer to highlight. You need to include pagination.
I'm not sure how pagination is a workaround here. For me, I have the same issue where it returns an empty set with a LastEvaluatedKey. When I paginate with this key, it doesn't return results that match my filter condition.