Reputation: 2129
I have a table that has the following fields:
uniqueID
startTime
endTime
value
otherData
Given a time range of 10:00AM today and 11:00AM today, I want to retrieve all the items where startTime
and endTime
fall between the aforementioned time range. Is there a way to do this efficiently?
I can think of one mediocre solution:
startTime
the range key.startTime
with condition of startTime
>= 10:00AM today. Then I will have to add a filter expression for endTime
<= 11:00AM today. The filtering part will be inefficient.Is there a better way for this in DynamoDB?
Upvotes: 2
Views: 1318
Reputation: 10566
3 methods:
1) your GSI approach
2) a Scan: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#QueryAndScan.Scan
May work for you if you don't have a lot of data
3) make startTime into the range key for the table and query on that (without a GSI)
If using the GSI keep in mind that they are eventually consistent (ie you might not get a record in your query after you immediately update it)
Upvotes: 3