Reputation: 424
I need to create a new table on AWS DynamoDB that will have a structure like the following:
{
"email" : String (key),
... : ...,
"someStuff" : SomeType,
... : ...,
"listOfIDs" : Array<String>
}
This table contains users' data and a list of strings that I'll often query (see listOfIDs
).
Since I don't want to scan
the table every time in order to get the user linked to that specific ID due to its slowness, and I cannot create an index since it's an Array and not a "simple" type, how could I improve the structure of my table? Should I use a different table where I have all my IDs and the users linked to them in a "flat" structure? Is there any other way?
Thank you all!
Upvotes: 0
Views: 411
Reputation: 2085
Perhaps another table that looks like:
ID string / hash key,
Email string / range key,
Any other attributes you may want to access
The unique combination of ID
and email
will allow you to search on the "List of IDs". You may want to include other attributes within this table to save you from needing to perform another query.
Upvotes: 1
Reputation: 16194
Should I use a different table where I have all my IDs and the users linked to them in a "flat" structure?
I think this is going to be your best bet if you want to leverage DynamoDB's parallelism for query performance.
Another option might be using a CONTAINS
expression in a query
if your listOfIDs
is stored as a set, but I can't imagine that will scale performance-wise as your table grows.
Upvotes: 1