php使用DynamoDB,php – 使用嵌套映射更新DynamoDB项的正确示例

我必须在这里遗漏一些简单的东西.此测试的目标是在现有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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值