编程语言
首页 > 编程语言> > php – 如何检查在dynamodb中的字符串集中存在的字符串

php – 如何检查在dynamodb中的字符串集中存在的字符串

作者:互联网

我在表格的每个项目中都设置了一个字符串.例如,

{                                        
   Title = "Book 101 Title"
   ISBN = "111-1111111111"
   Authors = "Author 1"
   Price = -2
   Dimensions = "8.5 x 11.0 x 0.5"
   PageCount = 500
   Color = [ "Red", "Black" ]
   ProductCategory = "Book" 
}


{                                        
   Title = "Book 102 Title"
   ISBN = "222-222222222"
   Authors = "Author 2"
   Price = -8
   Dimensions = "8.5 x 11.0 x 0.5"
   PageCount = 700
   Color = [ "Red", "Green" ]
   ProductCategory = "Book" 
}

使用dynamoDB php sdk,我希望获得“红色”颜色的项目.我试着这样.

$response = $client->query(array(
    "TableName" => $tablename,
    "KeyConditions" => array(
        "ComparisonOperator" => ComparisonOperator::CONTAINS,
        'Color' => array(
            'AttributeValueList' => array(
                array(Type::STRING_SET => array("Red"))
        ),
     )
));

但是我得到了这样的错误.

ValidationException: One or more parameter values were invalid: ComparisonOperator CONTAINS is not valid for SS AttributeValue type

解决方法:

我从aws开发者论坛here找到了一个解决方案.不能在查询中使用CONTAINS.必须使用扫描.像那样.

$response = $client->scan(array(
    "TableName" => $tablename,
    "KeyConditions" => array(
        "ComparisonOperator" => ComparisonOperator::CONTAINS,
        'Color' => array(
            'AttributeValueList' => array(
                array(Type::STRING => "Red")
        ),
     )
));

标签:php,amazon-dynamodb
来源: https://codeday.me/bug/20190830/1770281.html