我有一个Keys [key1,key2,key3]列表(在我的groups对象中作为NSArray),我想使用Objective-C找到DynamoDB Groups
表中的所有值。
应该是一个简单的任务,但我遇到了一个错误,我对如何为filterExpression
对象形成AWSDynamoDBScanExpression
感到困惑:
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;
}];
错误:
请求失败。错误:[错误域= com.amazonaws.AWSDynamoDBErrorDomain代码= 0“(null)”UserInfo = {__ type = com.amazon.coral.validate#ValidationException,message = Invalid FilterExpression:语法错误; token:“:val”,附近:“IN:val”}]
答案 0 :(得分:2)
如果你想找到你应该做的所有值
[[dynamoDBObjectMapper scan:[Group class] [AWSDynamoDBScanExpression new]] continueWithBlock:^id(AWSTask *task) {
//do stuff with (AWSDynamoDBPaginatedOutput obj).items -> should contain object of class Group
return nil;
}];
如果您想添加一些过滤器,可以配置AWSDynamoDBScanExpression
类似
AWSDynamoDBScanExpression *scanExpression = [[AWSDynamoDBScanExpression alloc] init];
scanExpression.expressionAttributeNames = @{
@"#P": [NSString stringWithFormat:@"%@", <propertyNameToFileter>]
};
scanExpression.filterExpression = @"#P = :val";
scanExpression.expressionAttributeValues = @{
@":val" : <filterCriteriaForProperty>
};
并调用相同的扫描方法。
在这两种情况下,你都会收到对象AWSDynamoDBPaginatedOutput
打印任务说明 - &gt; _result: AWSDynamoDBPaginatedOutput:0x7ff8faf56cc0