As per my data model, I need to store many to many relationship data items in dynamodb Example : I have a field called studentId and every studentId will have several subjects assigned to him.
Requirement :
So that for a given studentId, I need to store all the subjects. I would need to get all the subjects assigned to a given student.
Similary, for a given subjectId, I need to know the studentIds whom that subject has been assigned to.
am planning to store this in dynamoDb as follows :
- Table1 : StudentToSubjects :
- Hash Key : StudenId,
- RangeKey: subjectId
so that if I query using only primaryKey, it would give me all the rows having that primary key and all the different hash keys.
Secondary Key as
- secondary HashKey:
subjectId
- Secondary RangeKey:
studentId
I wanted to know if this makes sense or the right thing to do. Or there are better ways to solve this problem.