Scan with filter returns zero results in DynamoDB

1k Views Asked by At

I have a table with approximately 300 000 rows in DynamoDB. It contains three columns: source, data and cycles. The source attribute is a hash key and data is a range key. The cycles attribute is a number which is added by the application each time a row is to be added. I used to scan these rows with the following filter:

{
    TableName: "tableName",
    Limit: 20,
    ScanFilter: {
        cycles: {
            AttributeValueList: [
                {
                    N: "0"
                }
            ],
            ComparisonOperator: "EQ"
        }
    }
}

However, this scanfilter spontaneously seems to have decided not to work properly anymore. Anytime I execute this request it will return zero results. When I remove the scanfilter it returns 20 results, so I assume it has nothing to do with the limit or tableName attributes. The funny thing is that when I set the filter to find items with cycles equals "1" it actually works, maybe because there are 10 rows with cycles = 1 at the start of the table.

My question is simply how to fix this. Should I add a new index, or should I change this scanfilter? I can also try to use the query command instead of scan, but my previous attempts to do this didn't work out either.

1

There are 1 best solutions below

0
Prutser On

Never mind, I have to use the query method for this one. I noticed that the scan method only takes the first X number of rows from a table until the point when the scanFilter returns false, so it's not going to search the entire table.