gpt4 book ai didi

php - 使用搜索键条件的 DynamoDB 查询抛出一个奇怪的异常(使用 PHP)

转载 作者:行者123 更新时间:2023-12-02 04:57:58 25 4
gpt4 key购买 nike

我正在使用描述的方法查询 DynamoDB 表 here in the AWS PHP developer guide .

我传递给 Dynamo 连接的数组如下所示:

Array(
[ConsistentRead] => false
[TableName] => bbq_lol_test
[KeyConditions] => Array(
[stinky_cheese] => Array(
[ComparisonOperator] => EQ
[AttributeValueList] => Array(
[S] => camembert)

)
)
)

如您所见,除了 Type 枚举(它只是一个字符串)外,它的格式与示例使用的完全相同。

当以上述数组作为参数执行 $connection->query 时,出现以下异常:

Guzzle\Service\Exception\ValidationException: 
Validation errors: [KeyConditions][stinky_cheese][AttributeValueList][S][AttributeValue] must be of type object

这很奇怪,因为堆栈跟踪中的数组看起来没问题:

Aws/Common/Client/AbstractClient.php(103): Guzzle\Service\Client->__call("Query", array(array("ConsistentRead" => false, "TableName" => "bbq_lol_test", "KeyConditions" => array("stinky_cheese" => array("ComparisonOperator" => "EQ", "AttributeValueList" => array("S" => "camembert"))))))

DOstinky_cheese 字段上有一个索引(因为我正在使用查询)。我可能正在做一些愚蠢的事情,但我现在似乎无法弄清楚。任何帮助将不胜感激 - 谢谢!

最佳答案

有两个问题。

首先,AttributeValueList 应该是一个数组数组,而不是单个数组,从这里开始:

[AttributeValueList] => Array([S] => camembert)

对此:

[AttributeValueList] => Array(Array([S] => camembert))

因为可以在里面添加更多的东西,像这样:

[AttributeValueList] => Array(Array([S] => camembert), Array([S] => bleu))

第二个问题是我总是必须使用主哈希键进行查询,而我没有这样做。

关于php - 使用搜索键条件的 DynamoDB 查询抛出一个奇怪的异常(使用 PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17619849/

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