Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...