1
votes

Currently, I have a table in DynamoDB with this schema:


ID : PostID (Hash Key)

Location : LocationID (Range Key)

Tags: List of strings


Now I want to be able to query the Tags list and for each item in the table and find which Posts have those tags. How do I do that? Reading over the DynamoDB docs, I figure that I will have to set up another table since a Query cannot search specific strings in a List/String Set but I was not able to figure out how to structure the table.

For example, item:


PostID: Guid

Location: someLocationString

Tags: ["Queen", "Royalty", "England"]


Now I want to query for items that have a tag called "Queen" and I want the result to be a set of items that has the tag. (PostID + Location)

What would be the optimal structure? And how would I maintain the table when adding new tags?

1

1 Answers

1
votes

If I understand the requirements correctly you can go with a table:

Hash: Tag

Range: PostId#LocationId

That way you can query on Tag and get all the pairs.

Keeping both tables in sync is not optimal but it all depends how much atomicity is important to you. Perhaps look at DynamoDB Transactions, or do some "CAS" inserts.