Amazon dynamodb DynamoDB-通过GSI(PHP)更新项目
我正在尝试使用全局二级索引更新项目。下面列出了我的表定义。我是迪纳摩的新手Amazon dynamodb DynamoDB-通过GSI(PHP)更新项目,amazon-dynamodb,Amazon Dynamodb,我正在尝试使用全局二级索引更新项目。下面列出了我的表定义。我是迪纳摩的新手 $response = $this->client->createTable([ 'TableName' => 'rawproducts_products', 'AttributeDefinitions' => [ [ 'AttributeName' => 'product_code',
$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"
谁能给新手提个建议吗。非常感谢。它显示了这一点,因为您没有正确地传递密钥
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
如果要更新值,必须在表中而不是索引中更新
TableIndex不再受支持:输入中的未知参数:“TableIndex”必须是以下参数之一:TableName、Key、AttributeUpdate、Expected、ConditionalOperator、ReturnValues、ReturnConsumedCapacity、ReturnItemCollectionMetrics、UpdateExpression、ConditionalExpression、ExpressionAttributeNames、ExpressionAttributeValue