$ cond 사용 법 -- null 처리 법 ( sql 에 nvl )
.append("sucesCnt", new Document("$sum", new Document("$cond", new Document("if", new Document("$eq", Arrays.asList("1", "$sucesFlag"))) .append("then", 1) .append("else", 0)))) [{ $group: { _id: { $toString: '$apiSvcId' }, totalCount: { $sum: 1 }, failCount: { $sum: { $cond: { 'if': { $eq: [ '0', '$sucesFlag' ] }, then: 1, 'else': 0 } } } } }] $cond 사용 전에 $sum 을 해줘야 집계를 해서 group 할 수 있다.
2022. 3. 18.
MongoDB에서 * $subtract 과 $mod 사용법
new Document("_id",new Document("$toDate", new Document("$subtract", Arrays.asList(new Document("$toLong", "$cretDt"), new Document("$mod", Arrays.asList(new Document("$toLong", "$cretDt"), 10000))))) -- $group 함수 내부 { _id : { $toDate : { $subtract : { [ { $toLong : "$cretDt"} , { $mod : [ { $toLong : "$cretDt" } ,10000 ] } ] } } } } * $subtract- 빼기 함수 $mod - 나누기 함수 $cond - null 처리 함수
2022. 3. 18.