本文整理汇总了Java中org.springframework.data.mongodb.core.aggregation.Aggregation.limit方法的典型用法代码示例。如果您正苦于以下问题:Java Aggregation.limit方法的具体用法?Java Aggregation.limit怎么用?Java Aggregation.limit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.mongodb.core.aggregation.Aggregation
的用法示例。
在下文中一共展示了Aggregation.limit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJakduComments
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
public List<JakduComment> getJakduComments(String jakduScheduleId, ObjectId commentId) {
AggregationOperation match1 = Aggregation.match(Criteria.where("jakduScheduleId").is(jakduScheduleId));
AggregationOperation match2 = Aggregation.match(Criteria.where("_id").gt(commentId));
AggregationOperation sort = Aggregation.sort(Direction.ASC, "_id");
AggregationOperation limit = Aggregation.limit(Constants.COMMENT_MAX_LIMIT);
Aggregation aggregation;
if (Objects.nonNull(commentId)) {
aggregation = Aggregation.newAggregation(match1, match2, sort, limit);
} else {
aggregation = Aggregation.newAggregation(match1, sort, limit);
}
AggregationResults<JakduComment> results = mongoTemplate.aggregate(aggregation, "jakduComment", JakduComment.class);
List<JakduComment> comments = results.getMappedResults();
return comments;
}
示例2: findCommentsGreaterThanId
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
/**
* 기준 ArticleComment ID 이상의 ArticleComment 목록을 가져온다.
*/
@Override
public List<ArticleComment> findCommentsGreaterThanId(ObjectId objectId, Integer limit) {
AggregationOperation match1 = Aggregation.match(Criteria.where("_id").gt(objectId));
AggregationOperation sort = Aggregation.sort(Sort.Direction.ASC, "_id");
AggregationOperation limit1 = Aggregation.limit(limit);
Aggregation aggregation;
if (! ObjectUtils.isEmpty(objectId)) {
aggregation = Aggregation.newAggregation(match1, sort, limit1);
} else {
aggregation = Aggregation.newAggregation(sort, limit1);
}
AggregationResults<ArticleComment> results = mongoTemplate.aggregate(aggregation, Constants.COLLECTION_ARTICLE_COMMENT, ArticleComment.class);
return results.getMappedResults();
}