【问题标题】:DynamoDB get item countDynamoDB 获取项目计数
【发布时间】:2016-10-03 16:27:43
【问题描述】:

此代码返回整个项目集,我只需要它的计数。是否可以仅获取该索引的项目数?

    AWSDynamoDBObjectMapper *objectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
AWSDynamoDBQueryExpression *queryExpression = [AWSDynamoDBQueryExpression new];

queryExpression.indexName = @"getVideoViews";
queryExpression.keyConditionExpression = @"#videoId = :val";
queryExpression.expressionAttributeNames = @{
                                             @"#videoId" : @"videoId",
                                             };
queryExpression.expressionAttributeValues = @{
                                              @":val": videoId,
                                              };
__weak typeof(self) weakSelf = self;

[objectMapper query:[ViewedVideos class]
         expression:queryExpression
  completionHandler:^(AWSDynamoDBPaginatedOutput * _Nullable response, NSError * _Nullable error) {
      if (!error) {
          dispatch_async(dispatch_get_main_queue(), ^{
              if ([weakSelf.delegate respondsToSelector:@selector(serverConnectionHandlerReceivedNumberOfVideoViews:)]) {
                  [weakSelf.delegate serverConnectionHandlerReceivedNumberOfVideoViews:3];
              }
          });
      }
  }];

比如这里:

aws dynamodb scan --table-name <TABLE_NAME> --select "COUNT"

【问题讨论】:

  • 不熟悉objective-c或相应的sdk,但应该可以将“Select”参数设置为“COUNT”,就像在您的CLI示例中一样,不知何故。这是一个 Java 示例 stackoverflow.com/a/27327486/3484824

标签: ios objective-c amazon-web-services amazon-dynamodb aws-sdk-ios


【解决方案1】:

您可以使用DescribeTable API:http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html

有一个“itemCount”属性。请记住,这不是实时数据(每 6 小时更新一次)。因此,如果您要查找实时数据,则需要进行全表扫描。但是,不建议使用全表扫描,因为根据表的大小,它们可能会很昂贵。

【讨论】:

  • itemcount 是否适用于查询?因为,我不想要整个表的计数,而只想要具有该 videoID 的项目数。
  • 根据:docs.aws.amazon.com/amazondynamodb/latest/developerguide/…可以使用Count参数获取匹配过滤器/条件进行扫描/查询的项目总数
  • 是的,但它会返回所有项目,并且还有 count 参数。我只需要返回 count 参数,而不需要返回项目。抱歉,如果我遗漏了什么。
猜你喜欢
  • 2016-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 1970-01-01
相关资源
最近更新 更多