0

此代碼返回整套物品,我只需要計數它的數量。是否有可能只獲得這個索引的項目數?DynamoDB獲取物品計數

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" 

回答

1

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

有一個 「ITEMCOUNT」 屬性。請記住,這不是實時數據(每6小時更新一次)。因此,如果您正在查找實時數據,則需要執行全表掃描。但是,建議不要使用全表掃描,因爲根據桌子的大小,它們可能很昂貴。

+1

itemcount是否適用於查詢?因爲,我不希望整個表的數量,但只有具有該videoID項目的數量。 – vatti

+0

根據:http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html 您可以使用** Count **參數來獲取與過濾條件匹配的項目總數用於掃描/查詢 –

+0

是的,但它會返回所有項目,並且您還有count參數。我只需要返回count參數,而不是項目。對不起,如果我錯過了一些東西。 – vatti