本文整理汇总了Java中org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation方法的典型用法代码示例。如果您正苦于以下问题:Java Aggregation.newAggregation方法的具体用法?Java Aggregation.newAggregation怎么用?Java Aggregation.newAggregation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.mongodb.core.aggregation.Aggregation
的用法示例。
在下文中一共展示了Aggregation.newAggregation方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: findOrphans
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
public List<OrphanedTest> findOrphans(Collection<String> existingConfigurations) {
Aggregation aggregation = Aggregation.newAggregation(
match(Criteria.where("testName").nin(existingConfigurations)),
group("testName").max("created").as("latestCreatedDate").count().as("count"),
project("latestCreatedDate", "count").and("testName").previousOperation());
AggregationResults<OrphanedTest> orphanedTests = mongoTemplate.aggregate(aggregation,
DECISIONS_COLLECTION_NAME,
OrphanedTest.class);
return orphanedTests.getMappedResults();
}
示例4: findCommentsCountGreaterThanBoardIdAndBoard
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
/**
* boardItem의 boardId 기준 이상의 댓글 수를 가져온다
*
* @param boardId 기준이 되는 boardItem의 boardId
*/
@Override
public List<CommonCount> findCommentsCountGreaterThanBoardIdAndBoard(ObjectId boardId, Constants.BOARD_TYPE board) {
AggregationOperation match1 = Aggregation.match(Criteria.where("article._id").gt(boardId).and("article.board").is(board.name()));
AggregationOperation group = Aggregation.group("article").count().as("count");
AggregationOperation sort = Aggregation.sort(Sort.Direction.DESC, "count");
//AggregationOperation limit = Aggregation.limit(Constants.BOARD_TOP_LIMIT);
Aggregation aggregation = Aggregation.newAggregation(match1, group, sort/*, limit*/);
AggregationResults<CommonCount> results = mongoTemplate.aggregate(aggregation, Constants.COLLECTION_ARTICLE_COMMENT, CommonCount.class);
return results.getMappedResults();
}
示例5: findById
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
@Test
public void findById() {
ArrayList<ObjectId> arrTemp = new ArrayList<ObjectId>();
arrTemp.add(new ObjectId("54c4df893d96600d7f55a048"));
arrTemp.add(new ObjectId("54c4e4833d96deb0f8592907"));
AggregationOperation match = Aggregation.match(Criteria.where("_id").in(arrTemp));
//AggregationOperation group = Aggregation.group("article").count().as("count");
AggregationOperation sort = Aggregation.sort(Direction.ASC, "_id");
//AggregationOperation limit = Aggregation.limit(Constants.BOARD_LINE_NUMBER);
Aggregation aggregation = Aggregation.newAggregation(match, /*group, */ sort /*, limit*/);
AggregationResults<Gallery> results = mongoTemplate.aggregate(aggregation, "gallery", Gallery.class);
System.out.println("findOneById=" + results.getMappedResults());
}
示例6: getResults
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
@RequestMapping(value = "/results", method = RequestMethod.GET)
public ResponseEntity<Map<String, List<VoteCount>>> getResults() {
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.group("vote").count().as("count"),
project("count").and("vote").previousOperation(),
sort(Sort.Direction.DESC, "count")
);
AggregationResults<VoteCount> groupResults
= mongoTemplate.aggregate(aggregation, Vote.class, VoteCount.class);
List<VoteCount> results = groupResults.getMappedResults();
return new ResponseEntity<>(Collections.singletonMap("results", results), HttpStatus.OK);
}
示例7: updatedSince
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
@Override
public UpdatedConversationIds updatedSince(Date date) {
//IMPLEMENTATION NOTES (Rupert Westenthaler, 2017-07-19):
// * we need to use $gte as we might get additional updates in the same ms ...
// * Instead of $max: modified we would like to use the current Server time of the
// aggregation, but this is not possible ATM (see https://jira.mongodb.org/browse/SERVER-23656)
// * The use of $gte together with lastModified menas that we will repeat reporting the
// Entities updated at lastModified on every call. To avoid this a Workaround is used
// that increases the reported lastModified time by 1ms in cases no update was done
// since the last call (meaning the parsed date equals the lastModified)
Aggregation agg = date != null ? //if a date is parsed search for updated after this date
Aggregation.newAggregation(Aggregation.match(Criteria.where("lastModified").gte(date)),
ID_MODIFIED_PROJECTION, GROUP_MODIFIED) :
//else return all updates
Aggregation.newAggregation(ID_MODIFIED_PROJECTION, GROUP_MODIFIED);
log.trace("UpdatedSince Aggregation: {}", agg);
AggregationResults<UpdatedConversationIds> aggResult = mongoTemplate.aggregate(agg,Conversation.class,
UpdatedConversationIds.class);
if(log.isTraceEnabled()){
log.trace("updated Conversations : {}", aggResult.getMappedResults());
}
if(aggResult.getUniqueMappedResult() == null){
return new UpdatedConversationIds(date, Collections.emptyList());
} else {
UpdatedConversationIds updates = aggResult.getUniqueMappedResult();
//NOTE: workaround for SERVER-23656 (see above impl. notes)
if(date != null && date.equals(updates.getLastModified())) { //no update since the last request
//increase the time by 1 ms to avoid re-indexing the last update
return new UpdatedConversationIds(new Date(date.getTime()+1), updates.ids());
} else {
return updates;
}
}
}
示例8: getWinners
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
@RequestMapping(value = "/winners", method = RequestMethod.GET)
public ResponseEntity<Map<String, List<VoteCount>>> getWinners() {
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.group("vote").count().as("count"),
match(Criteria.where("count").is(getWinnersVotesInt())),
project("count").and("vote").previousOperation(),
sort(Sort.Direction.ASC, "vote")
);
AggregationResults<VoteCount> groupResults
= mongoTemplate.aggregate(aggregation, Vote.class, VoteCount.class);
List<VoteCount> results = groupResults.getMappedResults();
return new ResponseEntity<>(Collections.singletonMap("results", results), HttpStatus.OK);
}
示例9: latestDecisionForConfigurations
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
public Map<String, DateTime> latestDecisionForConfigurations() {
Aggregation aggregation = Aggregation.newAggregation(
project("testName", "created"),
group("testName").max("created").as("latestDecision"),
project("latestDecision").and("testName").previousOperation());
AggregationResults<LatestDecision> latestDecisions = mongoTemplate.aggregate(aggregation,
DECISIONS_COLLECTION_NAME,
LatestDecision.class);
return toMap(latestDecisions);
}
示例10: main
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
BasicQuery basicQuery = new BasicQuery("{apply_id:{$gt:800}}");
List<FkApply> find = mongoTemplate.find(basicQuery, FkApply.class);
System.out.println(find.size());
find.forEach(System.out::println);
// Projection Expressions
System.err.println("Projection Expressions");
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.project("apply_id", "apply_type"));
AggregationResults<OutputType> aggregate = mongoTemplate.aggregate(aggregation, "fk_qc_apply", OutputType.class);
aggregate.forEach(System.out::println);
}
示例11: getSupportFCCount
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
public List<SupporterCount> getSupportFCCount(String language) {
AggregationOperation match = Aggregation.match(Criteria.where("supportFC").exists(true));
AggregationOperation group = Aggregation.group("supportFC").count().as("count");
AggregationOperation project = Aggregation.project("count").and("_id").as("supportFC");
AggregationOperation sort = Aggregation.sort(Direction.DESC, "count");
Aggregation aggregation = Aggregation.newAggregation(match, group, project, sort);
AggregationResults<SupporterCount> results = mongoTemplate.aggregate(aggregation, "user", SupporterCount.class);
List<SupporterCount> users = results.getMappedResults();
for (SupporterCount supporterCount : users) {
supporterCount.getSupportFC().getNames().removeIf(fcName -> !fcName.getLanguage().equals(language));
}
return users;
}
示例12: 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;
}
示例13: 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();
}
示例14: findCommentsCountByIds
import org.springframework.data.mongodb.core.aggregation.Aggregation; //导入方法依赖的package包/类
/**
* 게시물 ID 에 해당하는 댓글 수를 가져온다.
*/
@Override
public List<CommonCount> findCommentsCountByIds(List<ObjectId> ids) {
AggregationOperation match = Aggregation.match(Criteria.where("article._id").in(ids));
AggregationOperation group = Aggregation.group("article").count().as("count");
//AggregationOperation sort = Aggregation.sort(Direction.ASC, "_id");
//AggregationOperation limit = Aggregation.limit(Constants.BOARD_LINE_NUMBER);
Aggregation aggregation = Aggregation.newAggregation(match, group/*, sort, limit*/);
AggregationResults<CommonCount> results = mongoTemplate.aggregate(aggregation, Constants.COLLECTION_ARTICLE_COMMENT, CommonCount.class);
return results.getMappedResults();
}