我是否从dynamodb以正确的方式获取数据?

时间:2017-05-18 23:38:12

标签: javascript amazon-web-services amazon-dynamodb

其实我是 dynamodb 的新手,文档对我来说很难掌握。虽然我不知道它是否有效,或者我是否遵循最佳实践,但我已经有了一个工作系统。所以任何帮助都将不胜感激。

我正在使用类似于以下结构的json对象:

**标题必须唯一

{ { "title": "a title", "des": "a description, "published:1495147723000 }, { "title": "a title 2", "des": "a description 2, "published:1495146489000 }, .... }

整个表格最多只包含200个项目。在这200件物品中,我需要的物品只在特定时间段之间发布。为了实现这一点,我正在使用这样的设置。我只是想知道是否有其他有效的方法来做这件事。

我的dynamodb表格模板:

{ TableName: 'Table', AttributeDefinitions: [{ AttributeName: "title", AttributeType: "S" }, { AttributeName: "published", AttributeType: "N" } ], KeySchema: [{ AttributeName: "title", KeyType: "HASH" }, { AttributeName: "published", KeyType: "RANGE" } ], GlobalSecondaryIndexes: [{ IndexName: "findByTime", KeySchema: [{ AttributeName: "title", KeyType: "HASH" }, { AttributeName: "published", KeyType: "RANGE" } ], Projection: { ProjectionType: "ALL" }, ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } }], ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } };

现在,我正在通过这样的扫描获取项目:

docClient.scan( { TableName: "Table", IndexName: "findByDate", FilterExpression: "feedTime BETWEEN :lastUpdate AND :now", // rangeKeyConditionExpression: "feedTime >= :ft", ExpressionAttributeValues: { ":now": Date.now(), ":lastUpdate": Number.parseInt(lastRefreshed) }, ScanIndexForward: false }, (e, r) => { if (e) { reject(e); } resolve(r); } );

1 个答案:

答案 0 :(得分:0)

  1. 您根本不需要全局二级索引。您可以直接查询表。仅当您希望散列键和范围键与主表不同时,才使用全局二级索引。目前,您支付的费用是配置容量的两倍。

  2. 使用扫描来获取记录似乎很好。

相关问题