本文整理汇总了Java中org.springframework.data.mongodb.core.aggregation.Aggregation类的典型用法代码示例。如果您正苦于以下问题:Java Aggregation类的具体用法?Java Aggregation怎么用?Java Aggregation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Aggregation类属于org.springframework.data.mongodb.core.aggregation包,在下文中一共展示了Aggregation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAppInfoByAppNames
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public List<ApplicationDTO> getAppInfoByAppNames(List<String> names) {
Aggregation aggregation = newAggregation(
match(Criteria.where("appname").in(names).and("timestamp").exists(true)),
sort(new Sort(DESC, "timestamp")),
project("appname", "platform", "starrating",
"timestamp", "comment", "authorName","url"),
group("appname", "platform")
.push(new BasicDBObject("author", "$authorName")
.append("rate", "$starrating" )
.append("timestamp", "$timestamp")
.append("comment", "$comment")
.append("url", "$url")
).as("reviews"),
project("appname", "platform")
.and("reviews").slice(8, 0)
);
//Convert the aggregation result into a List
AggregationResults<ApplicationDTO> groupResults
= mongoTemplate.aggregate(aggregation, Review.class, ApplicationDTO.class);
return groupResults.getMappedResults();
}
示例2: distinctTeams
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public Page<Team> distinctTeams(Pageable pageable) {
List<Team> teams = mongoTemplate.aggregate(
Aggregation.newAggregation(
group("team"),
sort(Sort.Direction.ASC, "_id.name"),
skip((long) pageable.getOffset()),
limit((long) pageable.getPageSize()),
replaceRoot("_id")
),
Submission.class, Team.class
).getMappedResults();
long totalCount = getTotalCount();
return new PageImpl<Team>(teams, pageable, totalCount);
}
示例3: getWinnersVotesInt
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
private int getWinnersVotesInt() {
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.group("vote").count().as("count"),
project("count"),
sort(Sort.Direction.DESC, "count"),
limit(1)
);
AggregationResults<VoteCountWinner> groupResults =
mongoTemplate.aggregate(aggregation, Vote.class, VoteCountWinner.class);
if (groupResults.getMappedResults().isEmpty()) {
return 0;
}
int result = groupResults.getMappedResults().get(0).getCount();
return result;
}
示例4: shouldRetrieveBooksPerPublisherWithTitles
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
/**
* Get number of books that were published by the particular publisher with their titles.
*/
@Test
public void shouldRetrieveBooksPerPublisherWithTitles() {
Aggregation aggregation = newAggregation( //
group("volumeInfo.publisher") //
.count().as("count") //
.addToSet("volumeInfo.title").as("titles"), //
sort(Direction.DESC, "count"), //
project("count", "titles").and("_id").as("publisher"));
AggregationResults<BooksPerPublisher> result = operations.aggregate(aggregation, "books", BooksPerPublisher.class);
BooksPerPublisher booksPerPublisher = result.getMappedResults().get(0);
assertThat(booksPerPublisher.getPublisher()).isEqualTo("Apress");
assertThat(booksPerPublisher.getCount()).isEqualTo(26);
assertThat(booksPerPublisher.getTitles()).contains("Expert Spring MVC and Web Flow", "Pro Spring Boot");
}
示例5: programIncrementBoardFeatures
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public List<String> programIncrementBoardFeatures(List<String> boards, List<String> programIncrementFeatures){
Aggregation agg = newAggregation(
match(Criteria
.where("sParentKey")
.in(programIncrementFeatures)
.and("keywords")
.in(boards)
),
group()
.addToSet("sParentKey")
.as("features"),
project("features")
.andExclude("_id")
);
AggregationResults<ProgramIncrementBoardFeatures> aggregationResult
= mongoTemplate.aggregate(agg, "feature", ProgramIncrementBoardFeatures.class);
return aggregationResult.getUniqueMappedResult() != null ? aggregationResult.getUniqueMappedResult().features : new ArrayList<>();
}
示例6: getRequestsWithCriteria
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
/**
* Helper that builds and runs the query. It creates a Match Operation, Group Operation and the Aggregation. The
* GroupOperation groups by caller, callee, calleeMethod and method name.
*
* @param matchCriteria
* {@link Criteria} which specifies the annotation and other filters
* @return {@link ClientRequestCollector} a list of matching requests
*/
private List<ClientRequestCollector> getRequestsWithCriteria(Criteria matchCriteria) {
// create match operation based on input
final MatchOperation matchOperation = match(matchCriteria);
// 1. group by caller
Fields fields = Fields.from(Fields.field(Ids.MICROSERVICE_CLIENT_REQUEST_ANNOTATION_FROM_ATTRIBUTE, "$" + ANNOTATION_FROM_ATTRIBUTE));
// 2. group by callee
fields = fields.and(Ids.MICROSERVICE_CLIENT_REQUEST_ANNOTATION_TO_ATTRIBUTE, "$" + ANNOTATION_TO_ATTRIBUTE);
// 3. group by callee method
fields = fields.and(Ids.MICROSERVICE_CLIENT_REQUEST_ANNOTATION_TO_METHOD_ATTRIBUTE, "$" + ANNOTATION_TO_METHOD_ATTRIBUTE);
// 4. group by name of method that contains the invocation
fields = fields.and(METHOD_PROJECTION, "$" + METHOD_ATTRIBUTE);
// create group operation
final GroupOperation groupOperation = group(fields).push("$" + TIME_FIELD).as(TIME_AGGREGATION_ATTRIBUTE);
final Aggregation microserviceClientAggregationSpec = newAggregation(matchOperation, groupOperation);
return aggregateProcedureExecution(microserviceClientAggregationSpec, ClientRequestCollector.class).getMappedResults();
}
示例7: getBacklogEstimateByKeywords
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public Double getBacklogEstimateByKeywords(List<String> boards) {
Aggregation agg = newAggregation(
match(Criteria
.where("keywords").in(boards)
.and("sSprintAssetState").ne("ACTIVE")
.and("sTypeName").in(Arrays.asList("Story","Bug"))
.and("sStatus").nin(Arrays.asList("Accepted", "Done"))
),
group()
.sum("dEstimate")
.as("value"),
project("value")
.andExclude("_id")
);
AggregationResults<DoubleValue> groupResults
= mongoTemplate.aggregate(agg, "feature", DoubleValue.class);
DoubleValue val = groupResults.getUniqueMappedResult();
return val == null ? 0 : val.value;
}
示例8: getSprintStatsByKeywords
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public SprintStats getSprintStatsByKeywords(List<String> boards) {
Aggregation agg = newAggregation(
match(Criteria
.where("keywords").in(boards)
.and("sSprintAssetState").is("CLOSED")
.and("sTypeName").in(Arrays.asList("Story","Bug"))
.and("sStatus").in(Arrays.asList("Accepted", "Done"))
),
group("sSprintName")
.first("sprintBeginDate").as("start")
.first("sprintEndDate").as("end")
.sum("dEstimate").as("estimate")
,
group()
.avg("estimate").as("estimateAvg")
.avg(
Ceil.ceilValueOf(
Divide.valueOf(
Subtract.valueOf("end").subtract("start")
).divideBy(3600 * 1000 * 24)
)
).as("daysDurationAvg"),
project("daysDurationAvg","estimateAvg")
.andExclude("_id")
);
AggregationResults<SprintStats> groupResults
= mongoTemplate.aggregate(agg, "feature", SprintStats.class);
return groupResults.getUniqueMappedResult();
}
示例9: getProductIncrementFromPiPattern
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public ProgramIncrementNamesAggregationResult getProductIncrementFromPiPattern(Pattern pi) {
Aggregation agg = newAggregation(
match(Criteria
//.where("keywords").in(boards)
.where("sPiNames").is(pi)
.and("sTypeName").is("Feature")
),
project("sPiNames")
.andExclude("_id"),
unwind("sPiNames"),
group()
.addToSet("sPiNames")
.as("piNames")
);
AggregationResults<ProgramIncrementNamesAggregationResult> aggregationResult
= mongoTemplate.aggregate(agg, "feature", ProgramIncrementNamesAggregationResult.class);
return aggregationResult.getUniqueMappedResult();
}
示例10: getLastReviewPerApplication
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public List<ApplicationReviewsDTO> getLastReviewPerApplication(List<String> names){
Aggregation aggregation = newAggregation(
match(Criteria.where("appname").in(names)),
sort(new Sort(DESC, "timestamp")),
group("appname", "platform")
.first("platform").as("platform")
.first("appname").as("appName")
.first("appname").as("appId")
.first("commentId").as("commentId")
);
//Convert the aggregation result into a List
AggregationResults<ApplicationReviewsDTO> groupResults
= mongoTemplate.aggregate(aggregation, Review.class, ApplicationReviewsDTO.class);
return groupResults.getMappedResults();
}
示例11: getAverageRateByAppNamesAfterTimestamp
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
@Override
public List<ApplicationDTO> getAverageRateByAppNamesAfterTimestamp(List<String> names, Long timestamp) {
Aggregation aggregation = newAggregation(
match(Criteria.where("appname").in(names).and("timestamp").gte(timestamp)),
group("appname", "platform")
.count().as("votesShortTerm")
.sum("starrating").as("ratingShortTerm")
);
//Convert the aggregation result into a List
AggregationResults<ApplicationDTO> groupResults
= mongoTemplate.aggregate(aggregation, Review.class, ApplicationDTO.class);
return groupResults.getMappedResults();
}
示例12: shouldRetrieveBooksPerPublisher
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
/**
* Get number of books that were published by the particular publisher.
*/
@Test
public void shouldRetrieveBooksPerPublisher() {
Aggregation aggregation = newAggregation( //
group("volumeInfo.publisher") //
.count().as("count"), //
sort(Direction.DESC, "count"), //
project("count").and("_id").as("publisher"));
AggregationResults<BooksPerPublisher> result = operations.aggregate(aggregation, "books", BooksPerPublisher.class);
assertThat(result).hasSize(27);
assertThat(result).extracting("publisher").containsSequence("Apress", "Packt Publishing Ltd");
assertThat(result).extracting("count").containsSequence(26, 22, 11);
}
示例13: shouldRetrieveDataRelatedBooks
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
/**
* Filter for Data-related books in their title and output the title and authors.
*/
@Test
public void shouldRetrieveDataRelatedBooks() {
Aggregation aggregation = newAggregation( //
match(Criteria.where("volumeInfo.title").regex("data", "i")), //
replaceRoot("volumeInfo"), //
project("title", "authors"), //
sort(Direction.ASC, "title"));
AggregationResults<BookAndAuthors> result = operations.aggregate(aggregation, "books", BookAndAuthors.class);
BookAndAuthors bookAndAuthors = result.getMappedResults().get(1);
assertThat(bookAndAuthors.getTitle()).isEqualTo("Spring Data");
assertThat(bookAndAuthors.getAuthors()).contains("Mark Pollack", "Oliver Gierke", "Thomas Risberg", "Jon Brisbin",
"Michael Hunger");
}
示例14: shouldRetrievePagesPerAuthor
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
/**
* Retrieve the number of pages per author (and divide the number of pages by the number of authors).
*/
@Test
public void shouldRetrievePagesPerAuthor() {
Aggregation aggregation = newAggregation( //
match(Criteria.where("volumeInfo.authors").exists(true)), //
replaceRoot("volumeInfo"), //
project("authors", "pageCount") //
.and(ArithmeticOperators.valueOf("pageCount") //
.divideBy(ArrayOperators.arrayOf("authors").length()))
.as("pagesPerAuthor"),
unwind("authors"), //
group("authors") //
.sum("pageCount").as("totalPageCount") //
.sum("pagesPerAuthor").as("approxWritten"), //
sort(Direction.DESC, "totalPageCount"));
AggregationResults<PagesPerAuthor> result = operations.aggregate(aggregation, "books", PagesPerAuthor.class);
PagesPerAuthor pagesPerAuthor = result.getMappedResults().get(0);
assertThat(pagesPerAuthor.getAuthor()).isEqualTo("Josh Long");
assertThat(pagesPerAuthor.getTotalPageCount()).isEqualTo(1892);
assertThat(pagesPerAuthor.getApproxWritten()).isEqualTo(573);
}
示例15: getAggregatedConfigurationWithRatingsById
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入依赖的package包/类
/**
* currently there is no support for reactive-aggregation.
*
* @see <a href="https://jira.spring.io/browse/DATAMONGO-1646">DATAMONGO-1646</a>
*/
@Override
public List<ConfigurationWithRatings> getAggregatedConfigurationWithRatingsById(String configurationId) {
// create lookup
LookupOperation lookupOperation = LookupOperation
.newLookup().from("rating").localField("_id").foreignField("configurationId").as("ratings");
Aggregation aggregation = Aggregation
.newAggregation(match(where("_id").is(configurationId)), lookupOperation);
List<ConfigurationWithRatings> results = mongoTemplate
.aggregate(aggregation, "configuration", ConfigurationWithRatings.class)
.getMappedResults();
return results;
}