Amazon dynamodb AWS-Dynamo:UpdateItem在索引GSI上引发错误

Amazon dynamodb AWS-Dynamo:UpdateItem在索引GSI上引发错误,amazon-dynamodb,Amazon Dynamodb,我正在尝试更新这样的元素 $response = $dynamo->updateItem(array( "TableName" => "posts", "IndexName" => "college_id-post_id-index", "Key" => array( "college_id" => array('S' => $collegeId), "post_id" => array('S' =

我正在尝试更新这样的元素

$response = $dynamo->updateItem(array(
    "TableName" => "posts",
    "IndexName" => "college_id-post_id-index",
    "Key" => array(
        "college_id" => array('S' => $collegeId),
        "post_id" => array('S' => $postId )
    ),
    "ExpressionAttributeValues" =>  array (
        ":reply" => $reply
    ),
    #"UpdateExpression" => "set reply = if_not_exists(reply , :reply)",
    "UpdateExpression" => "set reply = :reply",
    "ReturnValues" => 'ALL_NEW'
));


college_id-post_id-index is Global Secondary Index having hash key `college_id` and range key `post_id` . 
当我执行更新时,出现错误
提供的键元素与架构不匹配


有人能帮我解决什么问题吗?

如前所述,您能分享您的基表的模式吗

听起来您正试图直接更新表的GSI,这在DynamoDB中是不可能的。当您在DynamoDB表上创建GSI时,DynamoDB会跟踪GSI,并确保它会随着基表项的更新而自动更新

在本例中,假设您有一个基表(我不知道模式,但我会假设您有post_id作为散列键,college_id作为范围键)。您可以尝试以下稍加修改的代码:

$response = $dynamo->updateItem(array(
"TableName" => "posts",
"Key" => array(
    "post_id" => array('S' => $postId ),
    "college_id" => array('S' => $collegeId)
),
"ExpressionAttributeValues" =>  array (
    ":reply" => $reply
),
"UpdateExpression" => "set reply = :reply",
"ReturnValues" => 'ALL_NEW'
));
上述请求将更新基表中的相应项,但GSI也将更新以反映新值


您可以阅读有关基表和GSI之间数据同步的更多信息。

您可以粘贴可描述调用的输出吗?是否有一个以college_id和post_id作为散列键和范围键的基表模式?