Search code examples
rubyamazon-dynamodbdynamodb-queries

With DynamoDB.Client.Scan(), how do I retrieve all records where one attribute is not null?


With DynamoDB.Client.Scan(), how do I retrieve all records where one attribute is not null?

Something like:

res = db.scan({
    table_name: "Records", 
    filter_expression: "Fiction != :fiction", 
    expression_attribute_values: { 
        ":fiction" => nil
    }
})

Except of course that doesn't work


Solution

  • If you are looking for existing values, you should use the attribute_exists keyword, see the documentation

    filter_expression: "attribute_exists(Fiction)"

    Also, you are using the wrong comparator. DynamoDB uses <> and not != for inequality assertion. See documentation