dynamodb scanexpression with scan filter in object

2019-05-21 12:43发布

问题:

    AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
    AWSDynamoDBScanExpression *scanExpression = [AWSDynamoDBScanExpression new];
    scanExpression.exclusiveStartKey = nil;
    scanExpression.limit = @20;
    [[[dynamoDBObjectMapper scan:[DDBTableRow class]
                      expression:scanExpression]
      continueWithExecutor:[BFExecutor mainThreadExecutor] withSuccessBlock:^id(BFTask *task) { ................

I am able to scan through and return the first 20 recorded from a specific table from my DynamoDB as shows on a piece of code above.

The question now is I want to add a scanExpression.scanFilter = property but I haven't find any good direction on how to build that. I am using AWSiOSSDKv2 aws sdk for iOS on xcode6

here is what I have so far. It is not complete yet:

    AWSDynamoDBCondition *condition = [AWSDynamoDBCondition new];
    AWSDynamoDBAttributeValue *attribute = [AWSDynamoDBAttributeValue new];
    attribute.N = @"400";
    condition.comparisonOperator = AWSDynamoDBComparisonOperatorEQ;

    NSDictionary *scanFilter = @{@"lat":
                                     @{@"AttributeValueList":attribute,
                                       @"ComparisonOperator":@1}
                                 };
    scanExpression.scanFilter = scanFilter;

回答1:

You can use it as follows:

AWSDynamoDBCondition *condition = [AWSDynamoDBCondition new];
AWSDynamoDBAttributeValue *attribute = [AWSDynamoDBAttributeValue new];
attribute.N = @"400";
condition.attributeValueList = @[attribute];
condition.comparisonOperator = AWSDynamoDBComparisonOperatorEQ;
scanExpression.scanFilter = @{@"lat": condition};