查询Amazon DynamoDB以获取特定结果

时间:2014-10-22 15:00:57

标签: ios amazon-web-services amazon-dynamodb

我正在使用DynamoDB SDK v2。我可以扫描数据库但是我很难查询它以获得特定的结果。我不知道我的数据库设置是否错误,或者我的查询错误。

当我使用

- (void)getTableRow:(NSString *)rangeKey {
          AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
            [[dynamoDBObjectMapper load:[SonicUserTableRow class]
                                hashKey:@"UserId"
                               rangeKey:rangeKey] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
                if (!task.error) {

                   SonicUserTableRow *tableRow = task.result;

                   NSLog (@"Table Row %@", tableRow);

            } else {
               //Catch Error

            }
            return nil;
        }];
}

我使用[self getTableRow:@" ENTER UNIQUE USER ID "];

来调用它

但是我收到了错误

The provided key element does not match the schema

我该如何解决这个问题?

注意我正在使用新的Amazon SDK v2。

我的数据库 enter image description here

HASH&范围键

enter image description here

SonicUserTableRow .m

+ (NSString *)dynamoDBTableName {
    return @"SonicUsers";
}

+ (NSString *)hashKeyAttribute {
    return @"UserId";
}

+ (NSString *)rangeKeyAttribute {
    return @"Username";
}

SonicUserTableRow .h

@interface SonicUserTableRow : AWSDynamoDBModel <AWSDynamoDBModeling>

@property (nonatomic, strong) NSString *UserId;
@property (nonatomic, strong) NSString *Username;
@property (nonatomic, strong) NSString *profileImage;
@property (nonatomic, strong) NSString *active;
@property (nonatomic, strong) NSString *email;
@property (nonatomic, strong) NSString *flags;
@property (nonatomic, strong) NSString *attuned;

我在数据库中有UserId值UserIdString: us-east-1:4ae0a93a-59a6-45fd-80c8-ff6b99f1d152所以我试图调用例如:[self getTableRow:@"us-east-1:4ae0a93a-59a6-45fd-80c8-ff6b99f1d152"];

1 个答案:

答案 0 :(得分:0)

如果DropId是表格的哈希键,则可以使用- load:hashKey:rangeKey:加载单个项目。