DynamoDB:SET list_append无法使用AWS开发工具包 [英] DynamoDB : SET list_append not working using aws sdk

查看:73
本文介绍了DynamoDB:SET list_append无法使用AWS开发工具包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用相应的键将一个字符串附加到dynamodb表中设置的字符串中。这是我用来执行updateItem的Update表达式:

I need to append a string to a string set in a dynamodb table using the corresponding key. This is the Update expression I use to do updateItem :

  var params = {
    "TableName" : tableName,
    "Key": {
      "ID": {
        S: "20000"
      }
    },
    "UpdateExpression" : "SET #attrName = list_append(#attrName, :attrValue)",
    "ExpressionAttributeNames" : {
      "#attrName" : "entries"
    },
    "ExpressionAttributeValues" : {
      ":attrValue" : {"SS":["000989"]}
    }   };

当我使用aws cli执行updateItem()时,此方法有效。但是在nodejs中使用aws-sdk时,出现了错误:

This works when I do updateItem() using the aws cli. But when using aws-sdk in nodejs, I am getting the error:

Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: M\n

有什么帮助吗?
谢谢

Any help? Thanks

推荐答案

list_append 可以理解为连接操作。您只需给它两个列表即可。

list_append can be read as a "concatenate" operation. You just give it two lists.

"UpdateExpression" : "SET #attrName = list_append(#attrName, :attrValue)",
"ExpressionAttributeNames" : {
  "#attrName" : "entries"
},
"ExpressionAttributeValues" : {
  ":attrValue" : ["000989"]
}

值得记住的是,DynamoDB中的列表(和地图)没有键入并且可以存储任意数据。

It's worth remembering that lists (and maps) in DynamoDB are not typed and can store arbitrary data.

侧面说明:具备此知识,添加到列表开头的文档现在很有意义:

Side note: Armed with this knowledge, the documentation on appending to the beginning of the list now makes sense:


list_append(操作数,操作数)

此函数求值列表
中添加了新元素。您可以通过反转操作数的顺序将新元素添加到列表的
开头或结尾。

This function evaluates to a list with a new element added to it. You can append the new element to the start or the end of the list by reversing the order of the operands.

这篇关于DynamoDB:SET list_append无法使用AWS开发工具包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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