IT/java

java Mongodb gorup & max

역신 2024. 8. 5. 14:15
SMALL


--------- Obect 생성

MatchOperation matchOp = Aggregation.match(Criteria.where("upchecd").is(paramKey);

MatchOperation groupOp = Aggregation.group("upchecd).max("stdde").as("MAX_STDDE");


------------------
Aggregation agg = Aggregation.newAggregation(matchOp, projectOp).
  withOptions(Aggregation.newAggregationOptions()
.allowDiskUse(false)
.explain(false)
.cursor(new BasicDBObject()
.build()
);

DBObject dbobj mongoTemplate.aggregate(agg, "TB_TEST_INFO" , BasicDBObject.class).getRawResults();

List rst = null;
BasicDBOBject cursorObj = (BasicDBObject) dbobj.get("cursor");
BasicDBList resultList = (BasicDBList)cursorObj.get("firstBatch");
for(Object obj : resultList){
 .... 
}

LIST