자바 조작 mongodb Aggregation 그룹 조회

1346 단어
더 읽 기
첫 번 째 정적 클래스 가 져 오기

import static org.springframework.data.mongodb.core.aggregation.Aggregation.group;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.match;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.project;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort;

두 번 째 단계 

Aggregation agg = newAggregation(
        		DeviceStatisticsInfo.class,
        		//project("companyName","deviceModel").and("count").previousOperation(),
    			group("companyName","deviceModel").count().as("count"),
    			sort(Sort.Direction.DESC, "count")
    	);
        
        String collectionName = DeviceConstantTemplate.device_statistics_collection_name;
        
    	AggregationResults groupResults 
    			= mongoTemplate.aggregate(agg,collectionName,DeviceStatisticsInfo.class);
    		
    	List result = groupResults.getMappedResults();

좋은 웹페이지 즐겨찾기