DynamoDB : SET list_append not working using aws sdk

前端 未结 4 1521
南旧
南旧 2020-12-16 11:03

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 param         


        
4条回答
  •  北海茫月
    2020-12-16 11:38

    I thought I'd just throw this out there as another option for adding or appending an "object" to a list. It's a map being added an item to the list, and worked well for me:

    var upsertExpr = (obj.comments == undefined) ? " :attrValue" : "list_append(#attrName, :attrValue)";
    
    var params = {
        TableName: 'tableName',
        Key: {
            'id': {'S': id},
        },
        UpdateExpression : "SET #attrName = " + upsertExpr,
        ExpressionAttributeNames : {
          "#attrName" : "comments"
        },
        ExpressionAttributeValues : {
          ":attrValue" : {
                "L": [
                    { "M" : 
                        {
                            "comment": {"S": comment},
                            "vote": {"N": vote.toString()}
                        }
                    }
                ]
            }
        }
    };
    

提交回复
热议问题