我正在使用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。
我的数据库
HASH&范围键
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"];
答案 0 :(得分:0)
如果DropId
是表格的哈希键,则可以使用- load:hashKey:rangeKey:
加载单个项目。