我试图在DynamoDB中添加一个新的Map到List(评论),但我似乎无法正确使用它.下面是表格的简单结构:
{
"Comments": [
{
"Body": "This is the first comment",
"Username": "admin"
},
{
"Body": "This is the second comment",
"Username": "Jenny"
},
{
"Body": "This is the third comment",
"Username": "Bob"
}
],
"PostId": "RY28q1AxhR9Qi2VjrDdUdo5bPXBybUg2"
}
PHP代码:
$response = $ddb->updateItem (
[
'TableName' => 'comments',
'Key' => [
'PostId' => ['S' => $request->input('postid')]
],
"ExpressionAttributeNames" => ["#theList" => "Comments"],
"ExpressionAttributeValues" => [
':addVal' => [
'M' => [
'Username' => ['S' => 'MrSmith'],
'Body' => ['S' => 'Hello this is a comment'],
]
]
],
'UpdateExpression' => 'SET #theList = list_append(:addVal, #theList)',
]);
我收到此错误:
{
"result": 1,
"error": {
"message": "Error executing \"UpdateItem\" on \"https://dynamodb.us-east-1.amazonaws.com\"; AWS HTTP error: Client error: 400 ValidationException (client): Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: M - {\"__type\":\"com.amazon.coral.validate#ValidationException\",\"message\":\"Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: M\"}",
"status_code": "ValidationException"
}
任何帮助,将不胜感激.谢谢
编辑:仍然坚持这个问题,请帮忙吗?谢谢
解决方法:
我一直有同样的问题,思想在这里和那里有所解释,这是最终解决的问题
$res =$this->dynamodb->updateItem([
'TableName' => 'your_table',
'Key' => [
'key1' => ['N' => $detail1,
'key2' => ['S' => $detail2,
"ExpressionAttributeNames" => ["#theList" => "my_list_iten_name"],
"ExpressionAttributeValues" => [
':empty_list' => ['L'=>[]],
':addVal' => [
'L' => [
[
'M' => [
'val1' => ['S' => 'one'],
'val2' => ['S' => 'two!!!'],
]
],
[
'M' => [
'val1' => ['S' => 'one1'],
'val2' => ['S' => 'two2!!!'],
]
]
]
]
],
'UpdateExpression' => 'SET #theList = list_append(if_not_exists(#theList, :empty_list), :addVal)',
]);
标签:php,amazon-dynamodb,aws-sdk
来源: https://codeday.me/bug/20190519/1136312.html