使用 AWS DynamoDBScanExpression 查找列表中具有键的所有对象

using AWSDynamoDBScanExpression to find all objects with the key inside a list

我有一个键列表 [key1, key2, key3](在我的组对象中作为 NSArray),我想在我的 DynamoDB Groups table 中使用 Objective-C.

应该是一个简单的任务,但我遇到了一个错误,我对如何为 AWSDynamoDBScanExpression 对象形成 filterExpression 有点困惑:

AWSDynamoDBScanExpression *sc = [AWSDynamoDBScanExpression new];

sc.limit = @10;
sc.filterExpression = @"GroupID IN :val";
sc.expressionAttributeValues = @{@":val":groups};

[[dynamoDBObjectMapper scan:[Group class] expression:sc] continueWithBlock:^id(AWSTask *task) {
              if (task.error) {
                  NSLog(@"The request failed. Error: [%@]", task.error);
              }
              if (task.exception) {
                  NSLog(@"The request failed. Exception: [%@]", task.exception);
              }
              if (task.result) {
                  AWSDynamoDBPaginatedOutput *output = task.result;
                  NSArray *items = output.items; 
             }
              return nil;
          }];

错误:

The request failed. Error: [Error Domain=com.amazonaws.AWSDynamoDBErrorDomain Code=0 "(null)" UserInfo={__type=com.amazon.coral.validate#ValidationException, message=Invalid FilterExpression: Syntax error; token: ":val", near: "IN :val"}]

  1. 如果您想找到所有值,您应该按照以下步骤进行操作

    [[dynamoDBObjectMapper scan:[Group class] [AWSDynamoDBScanExpression new]] continueWithBlock:^id(AWSTask *task) {
        //do stuff with (AWSDynamoDBPaginatedOutput obj).items -> should contain object of class Group
        return nil;
    }];
    
  2. 如果你想添加一些过滤器,你可以配置AWSDynamoDBScanExpression类似

    的东西
    AWSDynamoDBScanExpression *scanExpression = [[AWSDynamoDBScanExpression alloc] init];
    
    scanExpression.expressionAttributeNames = @{
                                                @"#P": [NSString stringWithFormat:@"%@", <propertyNameToFileter>]
                                                };
    scanExpression.filterExpression = @"#P = :val";
    scanExpression.expressionAttributeValues = @{
                                                 @":val" : <filterCriteriaForProperty>
                                                 };
    

并调用相同的扫描方法。

在这两种情况下你都会收到对象 AWSDynamoDBPaginatedOutput

Printing description of task->_result: AWSDynamoDBPaginatedOutput: 0x7ff8faf56cc0