【发布时间】:2014-12-18 02:09:20
【问题描述】:
我正在使用 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。
我的数据库
哈希和范围键
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"];
【问题讨论】:
标签: ios amazon-web-services amazon-dynamodb