繁体   English   中英

查询Amazon DynamoDB以获取特定结果

[英]Query Amazon DynamoDB for specific result

我正在使用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 "];来调用它[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"];

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM