gpt4 book ai didi

amazon-dynamodb - DynamoDB - 通过 GSI 更新项目 (PHP)

转载 作者:行者123 更新时间:2023-12-04 00:39:25 24 4
gpt4 key购买 nike

我正在尝试使用全局二级索引更新项目。下面列出了我的表定义。我是 DynamoDb 的新手。

    $response = $this->client->createTable([
'TableName' => 'rawproducts_products',
'AttributeDefinitions' => [
[
'AttributeName' => 'product_code',
'AttributeType' => 'N'
],
[
'AttributeName' => 'token',
'AttributeType' => 'S'
],
[
'AttributeName' => 'processed_at',
'AttributeType' => 'N'
],
[
'AttributeName' => 'created_at',
'AttributeType' => 'N'
]
],
'KeySchema' => [
[
'AttributeName' => 'product_code',
'KeyType' => 'HASH'
],
[
'AttributeName' => 'token',
'KeyType' => 'RANGE'
]
],
'LocalSecondaryIndexes' => [
[
'IndexName' => 'ProductCodeProcessedIndex',
'KeySchema' => [
['AttributeName' => 'product_code', 'KeyType' => 'HASH'],
['AttributeName' => 'processed_at', 'KeyType' => 'RANGE']
],
'Projection' => [
'ProjectionType' => 'KEYS_ONLY',
],
],
[
'IndexName' => 'ProductCodeCreatedIndex',
'KeySchema' => [
['AttributeName' => 'product_code', 'KeyType' => 'HASH'],
['AttributeName' => 'created_at', 'KeyType' => 'RANGE']
],
'Projection' => [
'ProjectionType' => 'KEYS_ONLY',
],
]
],
'GlobalSecondaryIndexes' => [
[
'IndexName' => 'TokenIndex',
'KeySchema' => [
[ 'AttributeName' => 'token', 'KeyType' => 'HASH' ]
],
'Projection' => [
'ProjectionType' => 'ALL'
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1
]
]
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 6
]
]);

当我尝试使用以下查询更新属性“complete”时:

    $this->dynamoDb->updateItem([
'TableName' => $this->table,
'TableIndex' => 'TokenIndex',
'Key' => [
'token' => ['S' => (string)$this->token['S']]
],
'UpdateExpression' => 'set complete = :complete',
'ExpressionAttributeValues' => [
':complete' => ['N' => (string)1]
]
]);

但我不断收到以下错误:

    "The provided key element does not match the schema"

任何人都可以请教新手。非常感谢。

最佳答案

显示这个是因为你没有正确传递 key

You need to pass product_code and token both to update the value

其次

You cannot update value directly from GSI it's just a projection of the Table and not actual table

如果你想更新你必须在表中而不是在索引中更新的值

refer this link.

关于amazon-dynamodb - DynamoDB - 通过 GSI 更新项目 (PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34927711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com