假设我有一个staff
主键组成的表作为organization_id
分区键和排序键。另一方面,我有作为排序键的本地二级索引。staff_id
department
department_id
{
...
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" }
]
...
}
很容易发现,有许多不同的项目staff_id
共享相同的department
索引键。我需要用给定的组织查询部门列表organization_id
。有没有办法从staff
表中检索这个列表?我不喜欢维护另一个departments
表。我是 DynamoDB 的新手,所以如果您对整体表设计有任何意见/建议,非常欢迎。