I'm trying to familiarize myself with DynamoDB and I'm facing the following problem. My data record looks like this:
Crew{
id: string,
firstName: string,
lastName: string,
email: string,
roles: Role[],
address: Address
}
Role{
name: string
}
Address{
street: string,
zipCode: string,
city: string,
countryIsoCode: string
}
In DynamoDB, it would look like this:
PK | SK | GSI_PK1 | GSI_SK1 | GSI_PK2 | GSI_SK2 | Entity | Data |
---|---|---|---|---|---|---|---|
crewID#1 | crew | Crew | {firstName: 'Lex', lastName:'Luther', email: 'lext_luther@test.com', roles:[actor, director, writer]} | ||||
crewID#2 | crew | Crew | {firstName: 'Bruce', lastName:'Wayne', email: 'batman@test.com', roles:[actor]} | ||||
crewReqID#1 | req | CrewReq | CrewReq#2023-06-28-18:00:05 | {title: 'Batman Begins', shootingStart:'fall',crewReq:[ crewID#2, crewID#10]} |
I have the following access patterns that I need to solve without using a scan or multiple queries:
- I want to retrieve all Crew items that have roles x, y, or n.
- I want to retrieve all Crew items that have roles x, y, or n but do not appear in the crewReq attribute of crewReq#.
- I want to retrieve a specific crew item.
I thought about removing the 'roles' attribute from the 'Data' field and writing the item to the DB for each role once. This way, I could at least solve the first and third access pattern in a single query. However, I'm not sure how to solve the second requirement yet.
Moreover, it seems like this approach might be incorrect. I also believe that a third GSI (Global Secondary Index) is unnecessary.
Do you have any ideas or suggestions?