1
select * from tableName where columnName="value";

How can I fetch a similar result in DynamoDB using java, without using primary key as my attribute (Need to group data based on a value for a particular column).

I have gone through articles regarding getbatchitems, QuerySpec but all these require me to pass the primary key.

Can someone give a lead here?

1 Answer 1

1

Short answer is you can't. Whenever you use the Query or GetItem operations in DynamoDB you must always supply the table or index primary key.

You have two options:

  1. Perform a Scan operation on the table and filter by columnName="value". However this requires DynamoDB to look at every item in the table so it is likely to be slow and expensive.
  2. Add a Global Secondary Index to your table. This will require you to define a primary key for the index that contains the columnName you want to query
1
  • Thanks. Yes, I did not want to use 'Scan' for that reason. I will go with the 2nd option.
    – Mohanty
    Commented Jul 25, 2018 at 5:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.