具有限制结果的多个hashKey的AWS DynamoDB batchGetItem

时间:2016-01-22 11:26:05

标签: ios objective-c amazon-web-services amazon-dynamodb aws-sdk

我正在尝试减少查询多个hasKey值的时间,这就是为什么我们要查看batchGetItem。我对the sample project中的here的参考文件进行了一些小的更改{/ 3}}。

AWSDynamoDBKeysAndAttributes * keysAndAttributes = [ AWSDynamoDBKeysAndAttributes new ];
AWSDynamoDBAttributeValue * attributeValue1 = [ AWSDynamoDBAttributeValue new ];
attributeValue1.S = @"22";
AWSDynamoDBAttributeValue * attributeValue2 = [ AWSDynamoDBAttributeValue new ];
attributeValue2.S = @"18";

keysAndAttributes.keys = @[ @{ @"UserId" : attributeValue1 },
                            @{ @"UserId" : attributeValue2 } ];
keysAndAttributes.consistentRead = @YES;

AWSDynamoDBBatchGetItemInput * batchGetItemInput = [ AWSDynamoDBBatchGetItemInput new ];
batchGetItemInput.requestItems = @{ @"DynamoDB-OM-Sample" : keysAndAttributes };

AWSDynamoDB * awsDynamoDB = [ AWSDynamoDB defaultDynamoDB ];
[ [ awsDynamoDB batchGetItem: batchGetItemInput ]
        continueWithExecutor: [ AWSExecutor mainThreadExecutor ]
                   withBlock: ^ id ( AWSTask * task ) {

                       if ( task.result ) {
                           NSLog ( @"it's working!!" );
                       }
                       else {
                           NSLog ( @"not working... " );
                       }

                       return nil;
                   } ];

但它一直告诉我有一个错误:

The provided key element does not match the schema

另外我确实看到如何在AWSDynamoDBQueryExpression中设置限制,我们可以用batchGetItem做同样的事情吗?

0 个答案:

没有答案