0
votes

Say if I had a DynamoDB table:

UserId (hash): S
BookName (range): S
BorrowedTime: S
ReturnedTime: S

UserId is the primary key (hash), and I needed to set BookName as sort key (range) because another item being added to the database was overwriting the previous with the same UserId.

How would I go about creating a query using DynamoDBMapper, but the fields being queried are the time fields (which are non-keys)? For instance, say if I wanted to return the UserId and BookName of any book borrowed over 2 weeks ago that hasn't been returned yet?

Do I need to setup a GSI on both BorrowedTime and ReturnedTime fields?

1

1 Answers

0
votes

Yes you can make a GSI using BorrowedTime and ReturnedTime or you can use scan instead of a query , if you use scan you dont need to make a gsi but scan operations scan the whole database so it is not really recommended on large db or frequent use.