<legend id='9VvsC'><style id='9VvsC'><dir id='9VvsC'><q id='9VvsC'></q></dir></style></legend>
    <bdo id='9VvsC'></bdo><ul id='9VvsC'></ul>

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

      <small id='9VvsC'></small><noframes id='9VvsC'>

    2. <tfoot id='9VvsC'></tfoot>
      1. 如何更新 AWS DynamoDB 文档 API 上的地图或列表?

        时间:2023-06-27
          <tbody id='fgI91'></tbody>
          <bdo id='fgI91'></bdo><ul id='fgI91'></ul>

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

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

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

              <tfoot id='fgI91'></tfoot>
                  本文介绍了如何更新 AWS DynamoDB 文档 API 上的地图或列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  新的 AWS DynamoDB 文档 API 允许直接对应于底层 JSON 表示的 2 种新数据类型:地图 (又名 JSON 对象)和 List(又名 JSON 数组).

                  The new AWS DynamoDB document API allows 2 new data types that correspond directly to the underlying JSON representation: Map (aka JSON object) and List (aka JSON array).

                  但是,我找不到在不完全覆盖它们的情况下更新这些数据类型的属性的方法.相反,可以通过添加另一个数字来更新 Number 属性,因此在 Java 中您可以执行以下操作:

                  However, I can't find a way to update attributes of these data types without completely overwriting them. In contrast, a Number attribute can be updated by ADDing another number, so in Java you can do something like:

                  new AttributeUpdate("Some numeric attribute").addNumeric(17);
                  

                  同样,您可以addElements 到Set 数据类型的属性.(在旧 API 中,您可以同时使用 AttributeAction.ADD.)

                  Similarly you can addElements to an attribute of a Set data type. (In the old API you would use AttributeAction.ADD for both purposes.)

                  但是对于 Map 或 List,您似乎必须在本地更新以前的值,然后 PUT 代替那个值,例如在 Java 中:

                  But for a Map or a List, it seems you must update the previous value locally, then PUT it instead of that value, for example in Java:

                  List<String> list = item.getList("Some list attribute");
                  list.add("new element");
                  new AttributeUpdate("Some list attribute").put(list);
                  

                  这样的可读性要差得多,在某些情况下效率要低得多.

                  This is much less readable, and under some circumstances much less efficient.

                  所以我的问题是:

                  1. 有没有办法更新 Map 或 List 数据类型的属性而不覆盖以前的值?例如,将元素添加到 List,或将元素放入 Map?

                  1. Is there a way to update an attribute of a Map or a List data type without overwriting the previous value? For example, to add an element to a List, or to put an element in a Map?

                  您将如何使用 Java API 实现它?

                  How would you implement it using the Java API?

                  您知道将来支持此功能的计划吗?

                  Do you know of plans to support this in the future?

                  推荐答案

                  请查看 UpdateItem API

                  例如给定一个带有列表的项目:

                  For example given an item with a list:

                  {
                      "hashkey": {"S" : "my_key"},
                      "my_list" : {"L": 
                          [{"N":"3"},{"N":"7"} ]
                  }
                  

                  您可以使用如下代码更新列表:

                  You can update the list with code like the following:

                  UpdateItemRequest request = new UpdateItemRequest();
                  request.setTableName("myTableName");
                  request.setKey(Collections.singletonMap("hashkey", 
                      new AttributeValue().withS("my_key")));
                  request.setUpdateExpression("list_append(:prepend_value, my_list)");
                  request.setExpressionAttributeValues(
                      Collections.singletonMap(":prepend_value", 
                          new AttributeValue().withN("1"))
                      );
                  dynamodb.updateItem(request);`
                  

                  您还可以通过反转 list_append 表达式中参数的顺序来追加到列表.

                  You can also append to the list by reversing the order of the arguments in the list_append expression.

                  像这样的表达式: SET user.address.zipcode = :zip 将处理结合表达式属性值的 JSON 地图元素 {":zip" : {"N":"12345"}}

                  An expression like: SET user.address.zipcode = :zip would address a JSON map element combined with expression attribute values {":zip" : {"N":"12345"}}

                  这篇关于如何更新 AWS DynamoDB 文档 API 上的地图或列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将新的键值对放入 DynamoDB 中的映射中?(爪哇) 下一篇:有没有办法在 DynamoDB 中查询多个哈希键?

                  相关文章

                  <tfoot id='fAAtI'></tfoot>
                  <legend id='fAAtI'><style id='fAAtI'><dir id='fAAtI'><q id='fAAtI'></q></dir></style></legend>
                      <bdo id='fAAtI'></bdo><ul id='fAAtI'></ul>
                  1. <small id='fAAtI'></small><noframes id='fAAtI'>

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