如何更新字符串集(SS)类型的 Dynamodb 中的项目? [英] How to update an item in Dynamodb of type String Set (SS)?

查看:11
本文介绍了如何更新字符串集(SS)类型的 Dynamodb 中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个字符串集类型的属性.当我创建项目并分配 SS 类型的属性时,一切正常.但是当我尝试更新此属性时,数据类型会更改为列表(L").

I have created a attribute of type String Set. When I create the Item and assign an attribute of type SS everything works. But when I try to update this attribute, the data type changes to a list ("L").

我试试这个:

qw = new AWS.DynamoDB.DocumentClient();

var params = {
  TableName : "myTable",
  Key: {
    "id": somekey
  },
  UpdateExpression: "set ssvar= :arrp",
  ExpressionAttributeValues: {
     ":arrp": [ "test", "test2" ]
  }
};

qw.update (etc.)

这导致 dynamodb 中的数据类型发生变化,而不是字符串集,我得到一个列表:

This leads to a change in datatype in dynamodb and in stead of a string set I get a list:

"ssvar": {
            "L": [
                {
                    "S": "test"
                }, 
                {
                    "S": "test2"
                }
            ]
        }

我尝试了以下各种解决方案,但我的数据类型总是被改变.

I have tried all kinds of solutions like below but always my datatype gets changed.

  ExpressionAttributeValues: {
     ":arrp": 
        "SS": [ "test", "test2" ]
  }

如何更新字符串集类型的属性?

How can I update an attribute of type string set?

推荐答案

这是使用 DocumentClient 的神器 - StringSet 不是 JSON 类型.

This is an artifact of using the DocumentClient - StringSet is not a JSON type.

DocumentClient 将 StringSet 转换为 Array 原生 JavaScript 类型:https://github.com/aws/aws-sdk-js/blob/master/lib/dynamodb/converter.js#L61.然后客户端将原生 JavaScript 数组序列化为 DynamoDB 列表类型:https://github.com/aws/aws-sdk-js/blob/master/lib/dynamodb/converter.js#L12.

The DocumentClient converts a StringSet to the Array native JavaScript type: https://github.com/aws/aws-sdk-js/blob/master/lib/dynamodb/converter.js#L61. Then the client serializes the native JavaScript Array as a DynamoDB List type: https://github.com/aws/aws-sdk-js/blob/master/lib/dynamodb/converter.js#L12.

如果要使用 StringSet 类型,可以使用低级 API:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html

If you want to use the StringSet type, you can use the low-level API: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html

这篇关于如何更新字符串集(SS)类型的 Dynamodb 中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆