Querying DynamoDB by date

+2 votes
This question concerns AWS' Dynamo DB:

I have a table with a hash key and a range. Also a bunch of items in it.

I am specifically trying  to get all the items that were created after a specific date and sort them  by date. Which is pretty straightforward that is for a relational Database.

This was the problem however, to perform a query i need a hash key.

 by any means is my table schema wrong, now shouldn't the hash key be unique?
Apr 9, 2018 in Cloud Computing by hemant
• 5,750 points
7,350 views

10 answers to this question.

+1 vote
DynamoDB allows for specification of secondary indexes to aid in this sort of query. Secondary indexes can either be global, meaning that the index spans the whole table across hash keys, or local meaning that the index would exist within each hash key partition, thus requiring the hash key to also be specified when making the query.

For the use case in this question, you would want to use a global secondary index on the "CreatedAt" field.

This sort of queries are dealt in differently in DynamoDB due to the specification of Secondary indexes.These can be both global and local.

Global the span of index is across whole table. Where local means the hash key will have to be specified when making the query. Yourr problem will be benefited by Global . This is for the sake of reference : https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html
answered Apr 10, 2018 by brat_1
• 7,080 points
+1 vote
There are different query you can run on Dynamo DB. You can find the different queries here:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/EMRforDynamoDB.Querying.html?tag=duckduckgo-d-20
answered Oct 25, 2018 by nabarupa
+1 vote
Read the blog related to #dynamoDB. This blog covers all the different topics for the different query that can be implemented over Dynamo DB.
https://www.dynamodbguide.com/querying/
answered Oct 25, 2018 by kriti
+1 vote
You can use the "day" portion in the timestamp because of the hash function and use the full timestamp as the range.
answered Oct 25, 2018 by abc
0 votes
See the different method of querying in DynamoDb here

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html
answered Dec 10, 2018 by Sahil
0 votes
This article helps you get an idea on how to query your date

https://www.abhayachauhan.com/2017/12/how-to-store-dates-or-timestamps-in-dynamodb/
answered Dec 10, 2018 by Rishav
0 votes

You could use the "day" portion of the timestamp as the hash and use the full timestamp as the range.

answered Dec 10, 2018 by Shubham
0 votes

You could store the "year-month" portion of the timestamp as the hash key. That would significantly reduce the number of queries required when someone opens their app for the first time in, say, one year — compared to using the "day" portion.
At that point, it also seems that the range key becomes irrelevant, since querying by hash key would bring in all of the items that have been updated since 
lastRefreshedAt.

answered Dec 10, 2018 by User50729
0 votes

You could make the Hash key something along the lines of a 'unique' id, then the range key as a combination of a timestamp with a unique id appended on the end. That way you know the hash key and can still query the date with greater than.

answered Dec 10, 2018 by Rahul
0 votes

As per my understanding of these is that it should now allow you to perform the desired queries without having a full scan. The downside is that these indexes have to be specified at table creation, and also (I believe) cannot be blank when creating a unique item. So it's not a perfect solution, but a viable alternative, for some.

answered Dec 10, 2018 by findingbugs

Related Questions In Cloud Computing

0 votes
1 answer

DynamoDB: BatchGetItem vs Query

To a large extent I agree these ...READ MORE

answered Apr 17, 2018 in Cloud Computing by code_ninja
• 6,220 points
892 views
0 votes
1 answer

Can you filter through the created tags by using S3 file tagging?

You cannot filter with S3 file tagging ...READ MORE

answered May 8, 2018 in Cloud Computing by Meci Matt
• 9,420 points
20 views
0 votes
1 answer

AWS: What is the number of buckets that are created in by default?

100 buckets can be created in each ...READ MORE

answered Jul 10, 2018 in Cloud Computing by Meci Matt
• 9,420 points
46 views
0 votes
1 answer

How is AWS DynamoDB different from other AWS Databases?

Hi vishal, Amazon DynamoDB is a nonrelational database ...READ MORE

answered Oct 30, 2018 in Cloud Computing by remo12
32 views
+2 votes
5 answers

Possibility of Querying EC2 tags from within instance

You can use the describe-instances cli call ...READ MORE

answered Oct 25, 2018 in Cloud Computing by nabarupa
70 views
0 votes
3 answers

Increment the date in Java by 1-day

import java.time.LocalDate; public class DateIncrementer { static ...READ MORE

answered Aug 1, 2018 in Java by Akrati
• 3,150 points
583 views
0 votes
1 answer

How to display days data based on date selected in the filter by the user.

You can create a parameter for dates. Select data ...READ MORE

answered Aug 14, 2018 in Tableau by AwesomeSauce
• 860 points
63 views
0 votes
1 answer

How to list the contents of Amazon S3 by modified date?

One easy solution would be probably to ...READ MORE

answered Aug 21, 2018 in AWS by datageek
• 2,440 points
5,019 views