php使用DynamoDB,php – DynamoDB将新地图添加到列表

鞠边浩
2023-12-01

我试图在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"

}

任何帮助,将不胜感激.谢谢

编辑:仍然坚持这个问题,请帮忙吗?谢谢

 类似资料: