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

    <legend id='1D499'><style id='1D499'><dir id='1D499'><q id='1D499'></q></dir></style></legend>

    1. <small id='1D499'></small><noframes id='1D499'>

      1. <tfoot id='1D499'></tfoot>
          <bdo id='1D499'></bdo><ul id='1D499'></ul>

        使用哈希值数组的 AWS DynamoDB 扫描和 FilterExpress

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

              <tbody id='ExLl1'></tbody>

          • <small id='ExLl1'></small><noframes id='ExLl1'>

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

                  本文介绍了使用哈希值数组的 AWS DynamoDB 扫描和 FilterExpression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我很难找到在 DynamoDB 表上使用 FilterExpression 进行扫描的有用示例.我在浏览器中使用 javascript SDK.

                  I am having a hard time finding a useful example for a scan with FilterExpression on a DynamoDB table. I am using the javascript SDK in the browser.

                  我想扫描我的表并仅返回那些在我传递给 Scan 的数组中具有 HASH 字段UID"值的记录

                  I would like to scan my table and return only those records that have HASH field "UID" values within an array I pass to the Scan

                  假设我有一个唯一 id 数组,它们是我的表的哈希字段我想从我的 DynamoDB 表中查询这些记录.

                  Lets say I have an array of unique ids that are the hash field of my table I would like to query these records from my DynamoDB table.

                  如下图

                  var idsToSearch=['123','456','789'] //array of the HASH values I would like to retrieve
                  var tableToSearch = new AWS.DynamoDB();
                  var scanParams = {
                    "TableName":"myAwsTable",  
                    "AttributesToGet":['ID','COMMENTS','DATE'],  
                    "FilterExpression":"'ID' in "+idsToSearch+"" 
                  
                  }
                  tableToSearch.scan(scanParams), function(err,data){
                      if (err) console.log(err, err.stack); //error handler
                      else console.log(data); //success response
                  })
                  

                  推荐答案

                  你应该使用 IN 操作符.将 Placeholders 用于属性名称和属性值也更容易.不过,我建议不要在这种情况下使用 Scan.听起来您已经有了要查找的哈希键属性值,因此使用 BatchGetItem.

                  You should make use of the IN operator. It is also easier to use Placeholders for attribute names and attribute values. I would, however, advise against using a Scan in this case. It sounds like you already have the hash key attribute values that you want to find, so it would make more sense to use BatchGetItem.

                  无论如何,这就是你在 Java 中的做法:

                  Anyways, here is how you would do it in Java:

                  ScanSpec scanSpec = new ScanSpec()
                      .withFilterExpression("#idname in (:val1, :val2, :val3)")
                      .withNameMap(ImmutableMap.of("#idname", "ID"))
                      .withValueMap(ImmutableMap.of(":val1", "123", ":val2", "456", ":val23", "789"));
                  ItemCollection<ScanOutcome> = table.scan(scanSpec);
                  

                  我会想象使用 Javascript SDK 会是这样的:

                  I would imagine using the Javascript SDK it would be something like this:

                  var scanParams = {
                    "TableName":"myAwsTable",
                    "AttributesToGet": ['ID','COMMENTS','DATE'],
                    "FilterExpression": '#idname in (:val1, :val2, :val3)',
                    "ExpressionAttributeNames": {
                      '#idname': 'ID'
                    },
                    "ExpressionAttributeValues": {
                      ':val1': '123',
                      ':val2': '456',
                      ':val3': '789'
                    }
                  }
                  

                  这篇关于使用哈希值数组的 AWS DynamoDB 扫描和 FilterExpression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:AWS Lambda:如何将数字添加到 Dynamodb 中的 NS 集 下一篇:带有 DynamoDB 的 NodeJS 抛出错误“AttributeValue 可能

                  相关文章

                  最新文章

                  1. <small id='5kdCO'></small><noframes id='5kdCO'>

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