如何更新类型为字符串集(SS)的Dynamodb中的项目? [英] How to update an item in Dynamodb of type String Set (SS)?
问题描述
我创建了一个String Set类型的属性.当我创建Item并分配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屋!