当前位置: 首页>>代码示例>>Java>>正文


Java Aggregation.limit方法代码示例

本文整理汇总了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;
}
 
开发者ID:JakduK,项目名称:jakduk-api,代码行数:21,代码来源:JakdukDAO.java

示例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();
}
 
开发者ID:JakduK,项目名称:jakduk-api,代码行数:23,代码来源:ArticleCommentRepositoryImpl.java


注:本文中的org.springframework.data.mongodb.core.aggregation.Aggregation.limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。