【发布时间】:2020-08-07 22:36:42
【问题描述】:
我是 NoSQL DB 和无服务器的初学者。我的应用程序有一个名为Trips 的表。表格的参数是{id, route, cost, selling, type, date, LR, asset }和一堆其他不相关的文档编号,其中id是由uuid生成的。
现在我想查询数据库给我
- 使用日期参数返回一个日期范围内的所有行程。
- 使用日期和资产参数返回给定时间段内资产的所有行程。
- 使用日期路线参数返回给定时间段内路线的所有行程。
2 和 3 使用 keyConditionExpression 可以正常工作,但对于 1,我需要在扫描上使用 filterExpression 而不是查询,这可能会使其相对较慢,因为它是在查询完成后执行的。有没有更好的方法来形成架构?
在Trips 表中,架构是这样的
tripTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
[
{ "AttributeName": "id", "AttributeType": "S" },
{ "AttributeName": "date", "AttributeType": "S" },
{ "AttributeName": "Asset", "AttributeType": "S" },
{ "AttributeName": "Route", "AttributeType": "S" },
]
KeySchema:
[
{ "AttributeName": "date", "KeyType": "HASH" },
{ "AttributeName": "id", "KeyType": "RANGE" },
]
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
StreamSpecification:
StreamViewType: "NEW_AND_OLD_IMAGES"
TableName: ${self:provider.environment.TRIPS}
GlobalSecondaryIndexes:
- IndexName: TripsVSAssets
KeySchema:
- AttributeName: asset
KeyType: HASH
- AttributeName: date
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: "5"
WriteCapacityUnits: "5"
GlobalSecondaryIndexes:
- IndexName: RoutesVSAssets
KeySchema:
- AttributeName: route
KeyType: HASH
- AttributeName: date
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: "5"
WriteCapacityUnits: "5"
【问题讨论】:
标签: node.js database-design nosql amazon-dynamodb serverless