我必须在这里遗漏一些简单的东西.此测试的目标是在现有Map中设置新元素.以下PHP测试函数可以正常更新项目,但不是将person属性(Map)中间初始值设置为“T”,而是创建一个名为“person.mi”的新顶级属性并将其设置为“T” ”.
docs for Document Paths指定用于访问Map元素的点符号,所以….我不知道我缺少什么.
public function Z() {
$ddb = DynamoDbClient::factory(array('region' => 'us-east-1')); // EC2 role security
try {
$response = $ddb->updateItem(array(
"TableName" => "test",
"Key" => array("id" => array("N" => 1)),
"UpdateExpression" => "SET #fieldName = :value",
"ExpressionAttributeNames" => array("#fieldName" => "person.mi"),
"ExpressionAttributeValues" => array(":value" => array("S" => "T"))
));
} catch (Exception $e) {
throw new DDBException("Call to TestDDB->Z failed: " . $e->getMessage());
}
}
谁知道我哪里错了?谢谢.
解决方法:
这是因为点被认为是属性名称的一部分.您应该使用2个表达式属性名称.从documentation:
But what if you decided to use an expression attribute name instead?
For example, what would happen if you were to define #mmmk as a
substitute for MyMap.MyKey? DynamoDB would return an empty result,
instead of the expected string. This is because DynamoDB interprets a
dot in an expression attribute value as a character within an
attribute’s name. When DynamoDB evaluates the expression attribute
name #mmmk, it determines that MyMap.MyKey refers to a scalar
attribute—which is not what was intended.
The correct approach would be to define two expression attribute
names, one for each element in the document path:
#mm — MyMap
#mk — MyKey
You could then use the following projection expression:
#mm.#mk
标签:php,amazon-dynamodb
来源: https://codeday.me/bug/20190702/1361128.html