其實我是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); } );