DynamoDB:SET list_append 无法使用 aws sdk [英] DynamoDB : SET list_append not working using aws sdk

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

问题描述

我需要使用相应的键将字符串附加到 dynamodb 表中的字符串集.这是我用来做 updateItem 的更新表达式:

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

有什么帮助吗?谢谢

推荐答案

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 sdk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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