shaym2
shaym2

Reputation: 87

Filtering by non-key field in DynamoDB (aws-cli)

​i'm trying to query a number field in DynamoDB through aws-cli. It forces me to set the key (userId) to be something, although I want to retrieve all the users where the queriedField equals to 0. this is the syntax: ​

aws dynamodb query
--table-name TableName
--key-condition-expression "userId = :userid" 
--filter-expression "mapAttr.queriedField = :num"
--expression-attribute-values '{ ":userid": { "S": "<AccountID>" }, ":num" : { "N": "0" }}' 

Upvotes: 1

Views: 1376

Answers (1)

Matthew Pope
Matthew Pope

Reputation: 7669

In order to do this query, you will have to scan the whole table with your filter expression.

However, if this is for something that is still in development/design, consider making the 'number field' a top level attribute. That will allow you to create a GSI with a hash key of 'number field', and project the userId attribute to the GSI. Alternatively, you can use Global Secondary Index Write Sharding for Selective Table Queries

Upvotes: 1

Related Questions