【发布时间】:2016-11-11 18:56:58
【问题描述】:
我的 DynamoDB 架构是:
TableName = 'Cities'
PrimaryIndex = '_id'
SecondaryIndex = 'areaId-timestamp-index'
- areaId is primary key
- timestamp is sort key
DynamoDB 中的数据结构如下所示:
{ _id: '....', name: 'New York', areaId: 22, timestamp: 1478882557071 },
{ _id: '....', name: 'Washington', areaId: 22, timestamp: 1478882557071 },
{ _id: '....', name: 'Copenhagen', areaId: 18, timestamp: 1478882557071 },
{ _id: '....', name: 'Berlin', areaId: 12, timestamp: 1478882557071 },
我希望能够在以下条件下对城市进行分页:
- 仅限城市,fx,id 为 22 的地区
- 必须按照时间戳顺序分页
我的查询如下所示:
const areaId = 22
const params = {
TableName: 'Cities',
Limit: 10,
IndexName: 'areaId-timestamp-index',
KeyConditionExpression: 'areaId = :x',
ExpressionAttributeValues: {
':x': areaId
}
}
dynamo.query(params)
当我运行它时,我得到了预期的响应,lastEvaluatedKey
LastEvaluatedKey = {
areaId: 22,
_id: '8c43-d917-f9ec', // ID of last item in batch
timestamp: 1478882561962 // Timestamp of last item in batch
}
当我随后运行下一个后续查询(以获得更多结果)时,我添加了 ExclusiveStartKey 属性,其值与 LastEvaluatedKey 中返回的值完全相同。
但是,当我运行查询时,我得到:
The provided key element does not match the schema
【问题讨论】:
标签: node.js amazon-web-services pagination amazon-dynamodb