1

I have inherited a DynamoDB table with three columns of which one is a key

 Id - String - hashKey
 ProductID - String
 UsageCount - number

I want to run a query/scan that logically equates to the following

 select ProductID, UsageCount where ProductID='abcd'

Although ProductID is not a key of any sort, I can use the AmazonDynamoDB console and add a filter

console filter

and get just what I want. So I assume I should be able to do the same thing with code (although everyone talks about using hash and range keys for such purposes)

I am trying to do the same thing with RUBY but not getting results...

 resp = $dynamodb.scan(
       :table_name => PRODUCTTABLE,
       :projection_expression => "Id, TenantId, SeatCount",
          :filter_expression => 'TenantId = abcd'
                       )

Could someone help me with the correct syntax for doing this? I tried numerous variations that all throw exceptions except for the above syntax that does not throw an exception but returns zero rows. So Im thinking it must be close :) (or maybe not)

1 Answer 1

2

You have to use both filter_expression but make it 'TenantId = :val'

and then pass :val with expression_attribute_names and expression_attribute_values

Even though it's in Java, this doc will help clear things out for you

Sign up to request clarification or add additional context in comments.

1 Comment

thx! - the following syntax worked... resp = $dynamodb.scan( :table_name => "MyTable", :limit => 2, :projection_expression => "Id, DataSource, TenantId", :filter_expression => 'TenantId = :val', :expression_attribute_values => { ":val" => '6e874f58-ac9a-44ae-9ed4-9ed2e8828800' } )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.