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

          <bdo id='rr1YH'></bdo><ul id='rr1YH'></ul>
      1. <small id='rr1YH'></small><noframes id='rr1YH'>

      2. 如何更新 AWS DynamoDB 文档 API 上的地图或列表?

        时间:2023-09-28

          <tfoot id='Tz3fV'></tfoot>
          • <small id='Tz3fV'></small><noframes id='Tz3fV'>

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

                    <tbody id='Tz3fV'></tbody>

                  本文介绍了如何更新 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 上的地图或列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

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

                  相关文章

                  最新文章

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

                  <tfoot id='VGgQe'></tfoot>
                1. <small id='VGgQe'></small><noframes id='VGgQe'>

                2. <legend id='VGgQe'><style id='VGgQe'><dir id='VGgQe'><q id='VGgQe'></q></dir></style></legend>

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