Ios 查询Amazon DynamoDB以获取特定结果
我正在使用DynamoDB SDK v2。我可以扫描数据库,但我很难查询它的具体结果。我不知道我是否有数据库设置错误或我做的查询错误 当我使用Ios 查询Amazon DynamoDB以获取特定结果,ios,amazon-web-services,amazon-dynamodb,Ios,Amazon Web Services,Amazon Dynamodb,我正在使用DynamoDB SDK v2。我可以扫描数据库,但我很难查询它的具体结果。我不知道我是否有数据库设置错误或我做的查询错误 当我使用 - (void)getTableRow:(NSString *)rangeKey { AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper]; [[dynamoDB
- (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:@“输入唯一用户ID”]调用它代码>
然而,我得到的错误
The provided key element does not match the schema
我怎样才能解决这个问题
注意:我使用的是新的AmazonSDKV2
我的数据库
散列和范围键
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;
@接口SonicUserTableRow:AWSDynamodModel
@属性(非原子,强)NSString*UserId;
@属性(非原子,强)NSString*用户名;
@属性(非原子,强)NSString*profileImage;
@属性(非原子,强)NSString*活动;
@属性(非原子,强)NSString*电子邮件;
@属性(非原子,强)NSString*标志;
@属性(非原子,强)NSString*调谐;
我在数据库中有UserId值UserIdString:us-east-1:4ae0a93a-59a6-45fd-80c8-ff6b99f1d152
,因此我尝试调用示例:[self-getTableRow:@“us-east-1:4ae0a93a-59a6-45fd-80c8-ff6b99f1d152]
如果DropId
是表的散列键,则可以使用-load:hashKey:rangeKey:
加载单个项。我们的中有一个DynamoDB对象映射器示例。即使使用github,也要努力使其正常工作。用我所做的和悬赏奖更新了问题。您应该共享SonicUserTableRow
的定义(包括.h和.m文件)。可能未正确设置。您应该转到AWS管理控制台中的详细信息视图,确保看到主哈希键:hashKeyAttribute(String)
和主范围键:rangeKey(String)
。这些需要与+hashKeyAttribute
和+rangeKeyAttribute
返回的值相对应。我将它们更改为与AWS控制台中的值相匹配,现在我在返回字段中得到一个空值(尽管错误消失),即使我传递了我知道存在的ID。我觉得自己像个白痴。谢谢你的帮助