{
"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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…