【发布时间】:2014-08-11 11:10:58
【问题描述】:
这可能更像是一个 JS/Async 问题而不是 DynamoDB 特定问题 -
我想在 Amazon 的 DynamoDB 中使用哈希键获取表中的所有项目。该表中还包含 Range 键。
我正在使用一个 NodeJS 库,它是 AWS DynamoDB REST API 的包装器。 - Node-DynamoDB
DynamoDB 每次查询仅返回 1 MB 的结果。为了获取结果提醒,它包括 lastEvaluatedKey 。我们可以将其包含在另一个查询中,以获取另外 1 MB 的结果等等...
我在编写递归异步函数时遇到了困难,该函数应该按顺序访问服务,直到我可以取回所有结果。 (对于我的用例,表永远不会超过 10 MB,不会出现失控查询)
一些伪代码用于说明:
ddb.query('products', primarykey, {}, function(err,result){
//check err
if(result && result.lastEvaluatedKey){
//run the query again
var tempSet = result.items;
//temporarily store result.items so we can continue and fetch remaining items.
}
else{
var finalSet = result.items;
//figure out how to merge with items that were fetched before.
}
});
【问题讨论】:
标签: javascript node.js recursion amazon-web-services amazon-dynamodb