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,790 points
31,853 views

9 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,200 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

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,300 points
6,678 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,460 points
850 views
0 votes
2 answers

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

By Default,100 s3  buckets can be created ...READ MORE

answered Aug 5, 2020 in Cloud Computing by cloudkatha
• 210 points
983 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
703 views
0 votes
1 answer

Data sources supported by AWS clue

AWS Glue supports data stored in Amazon ...READ MORE

answered Nov 20, 2019 in Cloud Computing by Aleesha
652 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
2,413 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,190 points
4,551 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 15, 2018 in Tableau by AwesomeSauce
• 860 points
1,666 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP