Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
899 views
in Technique[技术] by (71.8m points)

node.js - DynamoDB : SET list_append not working using aws sdk

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"]}
    }   };

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

Any help? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"]
}

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 (operand, operand)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...