gpt4 book ai didi

ios - DynamoDB 获取项目计数

转载 作者:行者123 更新时间:2023-11-29 00:39:36 24 4
gpt4 key购买 nike

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

    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"

最佳答案

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

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

关于ios - DynamoDB 获取项目计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39836214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com