How to order in DynamoDB using the AWS SDK?

Currently, my range value is BigDecimal, reached by Time.now.to_f , and I want to get all user documents, for example:

 table = dynamo_db.tables['some_table'] table.load_schema docs = table.items.where(:user_id => user_id).select.map {|i| i.attributes} 

docs sorted in descending order .

+4
source share
1 answer

After digging into the SDK source code, I was able to find this little useful nugget for the AWS :: DynamoDB :: ItemCollection # query method

  # @option [Boolean] :scan_index_forward (true) Specifies which # order records will be returned. Defaults to returning them # in ascending range key order. Pass false to reverse this. 

Since my user_id is a hash value, I was able to reconsider my request:

 docs = table.items.query(:hash_value => user_id, :scan_index_forward => false).select.map {|i| i.attributes} 
+3
source

Source: https://habr.com/ru/post/1399694/


All Articles