javadoc_REF (많이쓸 클래스: async.client.mongoCollection)
- 부속: async-driver
<최근 dependency>
'org.mongodb:mongo-java-driver:3.4.2'
'org.mongodb:mongodb-driver-async:3.4.2'
이중화: https://nextus.tistory.com/26
aggregate사용법: 기초 REF , 프로그래밍 중에 사용법 REF
aggretate상세설명: REF
Async Code예제:REF
JAVA (Spring에서 aggregation 사용예제)
Criteria criteria = new Criteria("producerNo").is(producerNo);
MatchOperation match = Aggregation.match(criteria);
SortOperation sort = Aggregation.sort(Sort.Direction.DESC, "deliverStart");
Aggregation agg = Aggregation.newAggregation(match, sort);
AggregationResults<DeliverProduct> results = mongoTemplate.aggregate(agg, "deliverProduct", DeliverProduct.class);
List<DeliverProduct> productList = results.getMappedResults();
group의 경우
//SQL: db.xx.aggregate([{$group:{_id:{iotId:"$iotId", producerNo:"$producerNo"},
// deliverStart:{ $max:"$time"}}} ]
//RUN "group" Aggregation.//max(deliverStart)->deliverStart로
GroupOperation group = Aggregation.group("iotId", "producerNo").max("time").as("time");
Aggregation agg = Aggregation.newAggregation(group);
- 좀더 간단히 사용하려면 : REF (but, 추천은 아님)