Skip to content
Advertisement

How to query DynamoDB filtering by value in a list

There are three items in database:

JavaScript

With the year attribute being the table’s Primary Key I can go ahead and use the FilterExpression to match to the exact list value ["Action", "Biography"]:

JavaScript
JavaScript

Instead of matching an entire list ["Action", "Biography"] I would rather make a query to return only those table items that contain a string “Biography” in a list stored in the item’s info.genres field. I wonder if this possible using DynamoDB query API?

Edited later.

Working solution (Thanks to Balu) is to use QueryFilter contains comparison operator:

JavaScript

Advertisement

Answer

We can use contains in Filter expressions instead of =.

So, "info.genres = :genres" can be changed to contains(info.genres , :gnOne)

AWS is still going to query on Partition Key extract max 1 MB of data in single query before applying the filter. so, we will be charged with same RCU with or without filter expression but amount of data returned to client will be limited, so, still useful.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement