Amazon dynamodb 读取DynamoDB表的不同本地二级索引键
假设我有Amazon dynamodb 读取DynamoDB表的不同本地二级索引键,amazon-dynamodb,secondary-indexes,Amazon Dynamodb,Secondary Indexes,假设我有staff表,主键由organization\u id组成,作为分区键,staff\u id作为排序键。另一方面,我有department本地二级索引,其中department\u id作为排序键 很容易就可以看出,有许多项目具有不同的员工id共享相同的部门索引键。我需要查询具有给定组织\u id的组织的部门列表。有没有办法从staff表中检索此列表?我不喜欢维护另一个部门表。我是DynamoDB的新手,所以如果您对整个桌子的设计有任何意见/建议,我们非常欢迎 到目前为止,DynamoD
staff
表,主键由organization\u id
组成,作为分区键,staff\u id
作为排序键。另一方面,我有department
本地二级索引,其中department\u id
作为排序键
很容易就可以看出,有许多项目具有不同的
员工id
共享相同的部门
索引键。我需要查询具有给定组织\u id
的组织的部门列表。有没有办法从staff
表中检索此列表?我不喜欢维护另一个部门
表。我是DynamoDB的新手,所以如果您对整个桌子的设计有任何意见/建议,我们非常欢迎 到目前为止,DynamoDB中没有直接的distinct特性,但是您可以通过以下方法实现这一点
感谢到目前为止,DynamoDB中没有distinct的直接功能,但是您可以通过以下方式实现这一点
谢谢我最终维护了
部门
表。我最终维护了部门
表。
{
...
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" }
]
...
}