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
282 views
in Technique[技术] by (71.8m points)

Updating nested lists inside a dynamodb table

    {
      "Items": [
        {
          "0":{"id":"PrimaryKey"
                "comments":[
                     "0":{"commentId":"UniqueCommentID"
                           "text":"some comment text"
                          }
                           ]
              } 
        }
               ]
}

So I want to update the comment list which is having a unique commentId. For Appending the "comment" list I am using the following :

exports.handler = (event, context, callback) => {
console.log(event);
const params = {
    TableName: "tableName",
    Key: {
        "id": 'primaryKey',
    },
UpdateExpression : "SET #com = list_append(#com, :attrValue)",
ExpressionAttributeNames : {
  "#attrName" : "comment"
},
ExpressionAttributeValues : {
  ":attrValue" : [{
            "commentId":"unique",
            "text":" comment text"
             }]

        }]
},
ReturnValues: "UPDATED_NEW"
};
dynamodb.update(params, function(err, data) {
    if (err) {
        console.log(err);
        callback(err);
    } else {
        console.log(data);
        callback(null, data);
    }
});

Consider it as a comment in a blog post where "id" field denotes a blog id and "commentId" the comment id . I want to know how would I update/delete already existing comments in the "comment" list.

question from:https://stackoverflow.com/questions/65833045/updating-nested-lists-inside-a-dynamodb-table

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

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

...