tsukanomon
tsukanomon

Reputation: 1270

DynamoDB How to query a non-key attribute with strong consistency?

I have the following table in DynamoDB:

Table: Person

Attributes: person_id, firstName, lastName, age, birthday

Partition Key: person_id

My problem is: I need to query all the people that are between a certain age, for instance age > 18 AND age < 45.

However, I need strong consistency in my query, therefore, I cannot use a Global Secondary Index.

In this case what would be the best/possible solutions?

Upvotes: 0

Views: 754

Answers (2)

Mike Dinescu
Mike Dinescu

Reputation: 55720

What you are asking for is contradictory. If you need to get “all people with ages between 18 and 45”, unless this table is very very small, the set of people could change while you are querying. This is inherently the type of operation that is tolerant of eventual consistency.

I also wonder what you would do with the results.

If the the table is really big and you would have a lot of results for your query, how would you present the data?

If the table is always small then you can simply scan it and apply filters.

And ask yourself, what does it mean for a query or scan to be consistent? The very fact that a query/scan can take multiple round-trips to the server to complete means it won’t give you a point in time snapshot of the data. Unless the data is very small or changes infrequently.

Upvotes: 1

shubham singla
shubham singla

Reputation: 21

I would suggest you to use scan operation since you want to achieve filtering but you are not aware of the partition Key. In java, you can follow the below guide for scanning the table and using filter expressions. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ScanJavaDocumentAPI.html

Upvotes: 1

Related Questions