<bdo id='5onxd'></bdo><ul id='5onxd'></ul>
    <legend id='5onxd'><style id='5onxd'><dir id='5onxd'><q id='5onxd'></q></dir></style></legend>

    <small id='5onxd'></small><noframes id='5onxd'>

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

      2. AWS DynamoDb DocumentClient - 从项目数组创建 batchWrit

        时间:2023-09-03

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

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

          <legend id='gdNhe'><style id='gdNhe'><dir id='gdNhe'><q id='gdNhe'></q></dir></style></legend>

            • <tfoot id='gdNhe'></tfoot>
                <tbody id='gdNhe'></tbody>
              • <bdo id='gdNhe'></bdo><ul id='gdNhe'></ul>
                1. 本文介绍了AWS DynamoDb DocumentClient - 从项目数组创建 batchWrite - node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用来自项目数组 (JSON) 的 DynamoDB 的 DocumentClient 执行 batchWrite 操作

                  I'm trying to perform a batchWrite operation using DynamoDB's DocumentClient from an array of items (JSON)

                  这是我的代码:

                  var items = [];
                  
                  for (i = 0; i < orders.length; i++) {
                      var ord = orders[i]; //a simple json object
                      var item = { 
                          'PutRequest': { 
                              'Item' : ord[i] 
                          } 
                      };
                  
                      items.push(item);
                   }
                  
                  
                  var params = {
                      RequestItems: {
                          'my_table_name': items
                      }
                  };
                  
                  var docClient = new AWS.DynamoDB.DocumentClient();
                  
                  docClient.batchWrite(params, function(err, data) {
                  
                      if (err) {
                          console.log('There was a problem putting the items in the table');
                          context.fail(err);
                      } 
                      else {
                          console.log('Items updated in table');
                          context.done();
                      }
                  });
                  

                  我收到以下错误:

                  {"errorMessage":"Missing required key 'Item' in        
                   params.RequestItems['my_table_name']
                   [0].PutRequest","errorType":"MissingRequiredParameter"...
                  

                  我查看了 文档 但我不明白我在说什么我做错了.

                  I have looked at the documentation but I can't understand what I am doing wrong.

                  推荐答案

                  以下是正确的做法:

                  function batchWrite(arrayOf25) {
                  
                   //25 is as many as you can write in one time
                  
                    var itemsArray = [];
                  
                    for (i = 0; i < arrayOf25.length; i++) {
                  
                      var someItem = arrayOf25[i];
                      var item = {
                                  PutRequest: {
                                   Item: someItem
                                  }
                               };
                  
                  
                      if (item) {
                        itemsArray.push(item);
                      }
                  
                   }
                  
                  
                    var params = {
                        RequestItems: { 
                          'my_table_name': itemsArray
                        }
                      };
                  
                      //var AWS = require('aws-sdk'); //These should be added at the top
                      //var docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});
                  
                      docClient.batchWrite(params, function(err, data) {
                  
                        if (err) {
                            console.log(err); 
                        } 
                        else  {
                  
                            console.log('Added ' + itemsArray.length + ' items to DynamoDB');
                  
                        }   
                  
                  
                      });
                  
                  
                  }
                  

                  这篇关于AWS DynamoDb DocumentClient - 从项目数组创建 batchWrite - node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 NodeJS 将新对象附加到 DynamoDB 中的 JSON 数组 下一篇:使用 Lambda 查询 DynamoDB 没有任何作用

                  相关文章

                  最新文章

                  • <bdo id='wptHq'></bdo><ul id='wptHq'></ul>

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

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

                    <legend id='wptHq'><style id='wptHq'><dir id='wptHq'><q id='wptHq'></q></dir></style></legend>

                  1. <tfoot id='wptHq'></tfoot>