My Question could be similar to the below question
How to query for an entry that falls between start and end date - DynamoDB
but I think is different in terms of my requirement and what I am looking for.
For a particular Partition key value, I want to query all records for which current date lies between start-date and end-date.
My use case is that there would be Surveys created. Each Survey has a name and belongs to a Category. Each Survey has a Start Date and End Date. I need to query the names of all Active Surveys for a given Category, ie all Surveys, for a Category, for which Current Date lies between Start Date and End Date. Additionally, a Survey could be Active/Inactive.
What is have done so far:
Table Design: table tbl_surveys
Partition Key: tbl_pk_surv
Sort Key:tbl_sk_surv
One "Data" Attribute: data_attr
I created a GSI with tbl_sk_surv as Partition Key and data_attr as Sortkey.
I am creating 2 records for each Survey:
tbl_pk_surv |tbl_sk_surv|data_attr|cat_name|start_date|end_date|status
Surv-0tOrClRnTz| SURVEY | Survey1 | Cat1 |1564012800|1564876799|1
tbl_pk_surv | tbl_sk_surv | data_attr| survey_name | status
Surv-0tOrClRnTz | Cat1 | 1564012800-1564876799 | Survey1 | 1
So I put startdate and enddate in 1 column in the second record. My plan is, I want to query on GSI partition key value "Cat1", and get all Survey names for "Cat1". Please let me know how to query the GSI Sort key value 1564012800-1564876799, so that I can query between start date-end date.
Please note, that I put the first record, with static value "SURVEY" as value for pk_sk_surv attribute, so that I could query ALL survey records, by querying the GSI with "SURVEY" as partition key value. I am trying to implement single-table no-sql design.
I am new to NoSql Design, please guide me how to model data and query for my requirement.