메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

Cloudera CDH/CDP 및 Hadoop EcoSystem, Semantic IoT등의 개발/운영 기술을 정리합니다. gooper@gooper.com로 문의 주세요.


* MongoDB shell 구문을 Java Code로 표현하면 아래와 같다.

 db.employee.aggregate({$unwind: '$dp.fin.Record'},       
 {$match:{"dp.mon":"patch.metrics",'dp.fin.Record':{$exists:1}}},      
 {$group:{_id: '$dp.fin.Record', count:{$sum:1}}},      
 {$project:{count:'$count'}},   {$group:{_id:'Total
 Count',total:{$sum:'$count'}}});


-->

DBCollection table=null;
MongoClient mongoClient=null;
DB db = null;

mongoClient = new MongoClient(new ServerAddress(db_server, Integer.parseInt(db_port)));
db = mongoClient.getDB(db_name);
table = db.getCollection(collection_name);


//Forming Unwind parts
DBObject unwind = new BasicDBObject("$unwind","$dp.fin.record");

//Forming Match parts
DBObject match = new BasicDBObject();
match.put("dp.mon","patch.metrics");
match.put("dp.fin.Record", new BasicDBObject("$exists",1));

//Forming Group parts
DBObject group1 = new BasicDBObject();
group1.put("_id", "$dp.fin.Record");
group1.put("count", new BasicDBObject("$sum", 1));

//Forming Project parts
DBObject project = new BasicDBObject();
project.put("count", "$count");

//Forming Group parts
DBObject group2 = new BasicDBObject();
group2.put("_id", "Total Count");
group2.put("total", new BasicDBObject("$sum", "$count"));


/**
 * Executing aggregation 
 */
AggregationOutput output = table.getCollection("employee").aggregate(unwind,				                                                                            
          new BasicDBObject("$match",match),			                                                                            
          new BasicDBObject("$group",group1),				                                                                            
          new BasicDBObject("$project",project),				                                                                            
          new BasicDBObject("$group",group2));

// 결과확인		
System.out.println("output : "+output);;


번호 제목 날짜 조회 수
570 Tracking URL = N/A 가발생하는 경우 - 환경설정값을 잘못설정하는 경우에 발생함 2015.06.17 4618
569 root가 localhost에서 mysql로 접근하지 못하는 경우의 해결방법(패스워드) 2014.09.10 4618
568 Oozie 설치, 환경설정 및 테스트 2014.04.08 4613
567 oozie의 sqoop action수행시 ooize:launcher의 applicationId를 이용하여 oozie:action의 applicationId및 관련 로그를 찾는 방법 2023.07.26 4610
566 service name방식의 oracle을 메타정보 저장소로 사용할때 Hue Configuration설정하는 방법 2022.02.12 4610
565 [Hadoop Encryption] Encryption Zone에 생성된 table에 Hue에서 insert 수행시 User:hdfs not allowed to do 'DECRYPT_EEK' ON 'testkey' 오류 2023.11.01 4608
564 you are accessing a non-optimized hue please switch to one of the available addresses 2021.10.06 4608
563 hadoop nfs gateway설정 (Cloudera 6.3.4, CentOS 7.4 환경에서) 2022.01.07 4606
562 Hadoop wordcount 소스 작성 file 2013.03.06 4597
561 [Kerberos]병렬 kinit 호출시 cache파일이 손상되어 Bad format in credentials cache 혹은 No credentials cache found 혹은 Internal credentials cache error 오류 발생시 2023.01.20 4591
560 oozie webui접근시 id/pw를 물어보는 Windows보안 팝업창이 뜰때 확인/조치방법 2022.05.02 4591
559 unique한 값 생성 2014.04.25 4591
558 [TLS]TLS용 사설 인증서 변경 혹은 신규 지정시 No trusted certificate found 오류 발생시 확인및 조치사항 2022.03.15 4582
557 [CDP7.1.7]EncryptionZone에 table생성및 권한 테스트 2023.09.26 4580
556 hbase가 기동시키는 zookeeper에서 받아드리는 ip가 IPv6로 사용되는 경우가 있는데 이를 IPv4로 강제적용하는 방법 2015.05.08 4580
» mongodb aggregation query를 Java code로 변환한 샘플 2016.12.15 4576
554 [2.7.2] distribute-exclude.sh사용할때 ssh 포트변경에 따른 오류발생시 조치사항 2018.01.02 4575
553 column family삭제시 Column family 'delete' does not exist오류 발생하는 경우 2014.04.14 4574
552 kudu table와 impala(hive) table정보가 틀어져서 테이블을 읽지 못하는 경우(Error Loading Metadata) 조치방법 2023.11.10 4570
551 missing block및 관련 파일명 찾는 명령어 2021.02.20 4568
위로