Yas*_*aka 8 php amazon-dynamodb aws-sdk
我正在尝试将新的Map添加到DynamoDB中的列表(注释)中,但似乎无法正确完成。下面是该表的简单结构:
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
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)',
]);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。谢谢
编辑:仍然停留在这个问题上,请帮忙吗?谢谢
我曾经遇到过同样的问题,并且思想在这里和那里有所解释,这才是最终解决的问题
$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)',
]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2696 次 |
| 最近记录: |