Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamodb - scan items by value inside array

I'm doing a table scan. This table has an array as one of its fields, the "apps" field (apps is not a key of any kind). I want to select all rows, whose apps array contains a certain value "MyApp". I tried something of that kind, but my syntax is incorrect:

    ComparisonOperator = "#apps CONTAINS :v",
    ExpressionAttributeNames = {
        '#apps': 'apps'
    },
    ExpressionAttributeValues = {
        ":v": "MyApp"
    }

Thanks.

like image 963
Mister_L Avatar asked Mar 17 '16 10:03

Mister_L


People also ask

Does DynamoDB scan return all items?

A Scan operation in Amazon DynamoDB reads every item in a table or a secondary index. By default, a Scan operation returns all of the data attributes for every item in the table or index. You can use the ProjectionExpression parameter so that Scan only returns some of the attributes, rather than all of them.

Which is faster scan or Query in DynamoDB?

The Query operation took less than 65 milliseconds at the 95 percentile, compared to 650 milliseconds for Scan. In comparison to a query that conducts a straight lookup based on the partition key, response times vary substantially depending on the item and how the scan process works.

What is the difference between scan and Query in DynamoDB?

DynamoDB supports two different types of read operations, which are query and scan. A query is a lookup based on either the primary key or an index key. A scan is, as the name indicates, a read call that scans the entire table in order to find a particular result.


1 Answers

The documentation about Condition Expressions clearly states that the appropiate syntax is:

contains(#apps, :v)

The correct request would be:

FilterExpression: "contains(#apps, :v)",
ExpressionAttributeNames: { "#apps": "apps" },
ExpressionAttributeValues: { ":v": "MyApp" }
like image 182
Matias Cicero Avatar answered Sep 30 '22 09:09

Matias Cicero