- Newest
- Most votes
- Most comments
But I was also doubting about using just a single partitionkey with the syntax: customerid+_Mmonth+_Yyear. For example, if the customerid is 3322, january 2023 would be stored as: partitionkey = 3322_M01_Y2023 In this case no sort key would be needed. My main concern here is whether it will be efficient to query by "partition key ends with Y2023" when searching by year or "partitionkey contains M01" when searching by month. Which approach should I follow?
You cannot achieve either of those with a partition key. In DynamoDB you must provide the full value of the partition key. The sort key can be used for begins_with
or between
but not for ends_with
or contains
. If that sound confusing to you, read up on B+ tree sorting as thats what it resembles.
Another approach is storing the date as a Epoch time number as described here: Using Sort Keys to Organize Data in Amazon DynamoDB.
Relevant content
- Accepted Answerasked 2 years ago
- Accepted Answerasked 2 months ago
- asked 6 months ago
- asked 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 months ago
Ok, so once that option is discarded, taking into account the first approach, I could also do:
Yes, in that case you would also need the
customer id
. If your access pattern isGive me all the data for customer 123 between date 1 and date 2
then this will work well.You mean to also include the customerid in the sortkey? Something like 3322-2023-02-10 instead of just 2023-02-10?
No. Easier to ask what is your primary look-up pattern?
I'll need the following type of queries:
Having this information, I guess the partitionkey being the customerid is a must. But then, as we don't need to fetch specific days, we could only store the sortkey as year+month.