0

I am new to DynamoDB, and had a question how I can find all of the live entries in my DynamoDb table. Each entry in my table has a start and end date. I am confused on how I can query for the entries that the current date falls between the start and end date. Any ideas how I can do this?

I understand that I can only have a primary and range key. Is it possible to query for other columns in the entry?

Each entry looks like this:

id: xxxxxx startDate: 123456 // Epoch time endDate: 334243 // Epoch time

thunderousNinja
  • 3,510
  • 9
  • 37
  • 49
  • 1
    Do you know the `id` you want to query against? If not, you will have to use a `Scan`. – mkobit May 01 '15 at 05:29
  • @mkobit In my case, I have a partition key value available, for example 'Cat1', the name of a category. How to model data and how to query, if I have to query all categories between a start date and end date ? Presently, I put start date and enddate together in Sort Key, for example 1563840000-1565654399 ie separated by -. How to query this ? I want to post a question on this, but it would be similar to this question, Please atleast let me know how to draft a proper new question based on my requirement. – Bhargava Aug 09 '19 at 06:50

2 Answers2

1

If you do not know the hashkey of your item(looks like 'id' in your case) then the only way to query DynamoDB is using a full table scan.

You can do a table scan using multiple conditions, but this is inefficient.

prestomation
  • 7,225
  • 3
  • 39
  • 37
  • I do have a partition key value, since I am using a GSI, could you please tell the best way to query for a records start date and end date ? – Bhargava Jul 19 '19 at 14:38
-3

First you'll need to establish current epoch time. Then you can look to see if current epoch falls between your start and end epoch times. Most SQL variants have a BETWEEN(now, start, end) function. If not, then you'd look for now >= start AND now <= end. And yes, you can return any column in your query.

MrCleanX
  • 416
  • 2
  • 13