<bdo id='tWYLG'></bdo><ul id='tWYLG'></ul>
      <tfoot id='tWYLG'></tfoot>

      <i id='tWYLG'><tr id='tWYLG'><dt id='tWYLG'><q id='tWYLG'><span id='tWYLG'><b id='tWYLG'><form id='tWYLG'><ins id='tWYLG'></ins><ul id='tWYLG'></ul><sub id='tWYLG'></sub></form><legend id='tWYLG'></legend><bdo id='tWYLG'><pre id='tWYLG'><center id='tWYLG'></center></pre></bdo></b><th id='tWYLG'></th></span></q></dt></tr></i><div id='tWYLG'><tfoot id='tWYLG'></tfoot><dl id='tWYLG'><fieldset id='tWYLG'></fieldset></dl></div>
      1. <legend id='tWYLG'><style id='tWYLG'><dir id='tWYLG'><q id='tWYLG'></q></dir></style></legend>

        <small id='tWYLG'></small><noframes id='tWYLG'>

        使用 Node JS 递归获取 DynamoDB 查询中的所有项目

        时间:2023-09-03
      2. <legend id='AMtHb'><style id='AMtHb'><dir id='AMtHb'><q id='AMtHb'></q></dir></style></legend>

          <bdo id='AMtHb'></bdo><ul id='AMtHb'></ul>

            <tbody id='AMtHb'></tbody>
        • <tfoot id='AMtHb'></tfoot>
            • <i id='AMtHb'><tr id='AMtHb'><dt id='AMtHb'><q id='AMtHb'><span id='AMtHb'><b id='AMtHb'><form id='AMtHb'><ins id='AMtHb'></ins><ul id='AMtHb'></ul><sub id='AMtHb'></sub></form><legend id='AMtHb'></legend><bdo id='AMtHb'><pre id='AMtHb'><center id='AMtHb'></center></pre></bdo></b><th id='AMtHb'></th></span></q></dt></tr></i><div id='AMtHb'><tfoot id='AMtHb'></tfoot><dl id='AMtHb'><fieldset id='AMtHb'></fieldset></dl></div>

              <small id='AMtHb'></small><noframes id='AMtHb'>

                  本文介绍了使用 Node JS 递归获取 DynamoDB 查询中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这可能更像是一个 JS/Async 问题而不是 DynamoDB 特定问题 -

                  This is probably more of an JS/Async question than a DynamoDB specific question -

                  我想在 Amazon 的 DynamoDB 中使用哈希键获取表中的所有项目.该表中还包含 Range 键.

                  I want to fetch all the items in a table with a hash key in Amazon's DynamoDB. The table also has Range key in it.

                  我正在使用一个 NodeJS 库,它是 AWS DynamoDB REST API 的包装器.-节点-DynamoDB

                  I am using a NodeJS library which is a wrapper around AWS DynamoDB REST API. - Node-DynamoDB

                  DynamoDB 每次查询仅返回 1 MB 的结果.为了获取结果提醒,它包括 lastEvaluatedKey .我们可以将其包含在另一个查询中,以获取另外 1 MB 的结果等等...

                  DynamoDB only returns 1 MB worth of results with each query. To fetch reminder of results, it includes lastEvaluatedKey . We can include this in another query to fetch another 1 MB worth of results and so on...

                  我在编写递归异步函数时遇到了困难,该函数应该按顺序访问服务,直到我可以取回所有结果.(对于我的用例,表永远不会超过 10 MB,不会出现失控查询)

                  I am facing difficulty in writing a recursive async function which should hit the service sequentially till i can get all the results back. (table will never have more than 10 MB for my use case, no chance of a runaway query)

                  一些伪代码用于说明:

                  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.
                      }
                  });
                  

                  推荐答案

                  var getAll = function(primarykey, cb) {
                      var finalSet = [],
                          nextBatch = function(lek) {
                              ddb.query('products', primarykey, {
                                  exclusiveStartKey: lek
                              }, function(err, result) {
                                  if (err) return cb(err);
                  
                                  if (result.items.length)
                                      finalSet.push.apply(finalSet, result.items);
                  
                                  if (result.lastEvaluatedKey)
                                      nextBatch(result.lastEvaluatedKey);
                                  else
                                      cb(null, finalSet);
                              });
                          };
                  
                      nextBatch();
                  };
                  
                  
                  getAll(primarykey, function(err, all) {
                      console.log(err, all);
                  });
                  

                  这篇关于使用 Node JS 递归获取 DynamoDB 查询中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:DynamoDB - 如何在一次更新中创建地图并向其添加属 下一篇:在 dynamodb 中使用 batchWriteItem

                  相关文章

                  最新文章

                  <legend id='lwLgA'><style id='lwLgA'><dir id='lwLgA'><q id='lwLgA'></q></dir></style></legend>
                • <small id='lwLgA'></small><noframes id='lwLgA'>

                      <i id='lwLgA'><tr id='lwLgA'><dt id='lwLgA'><q id='lwLgA'><span id='lwLgA'><b id='lwLgA'><form id='lwLgA'><ins id='lwLgA'></ins><ul id='lwLgA'></ul><sub id='lwLgA'></sub></form><legend id='lwLgA'></legend><bdo id='lwLgA'><pre id='lwLgA'><center id='lwLgA'></center></pre></bdo></b><th id='lwLgA'></th></span></q></dt></tr></i><div id='lwLgA'><tfoot id='lwLgA'></tfoot><dl id='lwLgA'><fieldset id='lwLgA'></fieldset></dl></div>
                      <tfoot id='lwLgA'></tfoot>
                        <bdo id='lwLgA'></bdo><ul id='lwLgA'></ul>