gruuuvy
gruuuvy

Reputation: 2129

Query for a time range from startTime and endTime fields in DynamoDB?

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:

  1. Make a GSI with a hash key based on hour in the day for even partitioning, and make the startTime the range key.
  2. This way I can query for a 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

Answers (1)

Mircea
Mircea

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

Related Questions