Assume I have staff
table with primary key composing of organization_id
as partition key and staff_id
as sort key. On the other hand I have department
local secondary index with department_id
as sort key.
{
...
KeySchema: [
{ AttributeName: "organization_id", KeyType: "HASH"},
{ AttributeName: "staff_id", KeyType: "RANGE" }
],
LocalSecondaryIndexes: [
{
IndexName: "department",
KeySchema: [
{ AttributeName: "organization_id", KeyType: "HASH"},
{ AttributeName: "department_id", KeyType: "RANGE" }
],
Projection: {
ProjectionType: "KEYS_ONLY"
}
}
],
AttributeDefinitions: [
{ AttributeName: "organization_id", AttributeType: "S" },
{ AttributeName: "staff_id", AttributeType: "S" },
{ AttributeName: "department_id", AttributeType: "S" }
]
...
}
As one may easily figure out, there are many items with different staff_id
sharing same department
index key. I need to query list of departments of an organization with given organization_id
. Is there a way to retrieve this list from staff
table? I do not prefer to maintain another departments
table. I am new to DynamoDB, so if you have any comments/advices on overall table design, all is very welcome.