반응형
//컬렉션 초기화
MongoCollection<Document> auditLogCol = mongoTemplate.getCollection("AUDIT_LOG");

//where 조건 쿼리
BasicDBObject dateTermQuery = MogoDBUtil.getDateTermFindQuery("body_event_time", vo.getStartDate(), vo.getEndDate());
dateTermQuery.put("body_host_ip", vo.getHostIp());
        
List<BasicDBObject> uidQueryList = new ArrayList<BasicDBObject>();

//$match 부분 초기화
BasicDBObject matchQuery = new BasicDBObject("$match", dateTermQuery);
//$group 부분 추기화
BasicDBObject groupUidQuery = new BasicDBObject("$group", new BasicDBObject("_id", "$body_uid"));
		
uidQueryList.add(matchQuery);
uidQueryList.add(groupUidQuery);
//aggregate 요청
List<Document> uidList = auditLogCol.aggregate(uidQueryList).into(new ArrayList<>());
728x90

'[개발관련] > Database(MongoDB)' 카테고리의 다른 글

인덱스 생성/삭제 쿼리  (0) 2021.01.30
몽고DB import/exprot 쿼리  (0) 2020.12.26
MySql, MongoDB 문법비교 그림  (0) 2020.12.09
몽고디비란?  (0) 2019.12.23

+ Recent posts