첫번째 예제) 하나의 도큐먼트를 sizes의 배열 요소로 분리함{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] } db.inventory.aggregate( [ { $unwind : "$sizes" } ] ) { "_id" : 1, "item" : "ABC1", "sizes" : "S" } { "_id" : 1, "item" : "ABC1", "sizes" : "M" } { "_id" : 1, "item" : "ABC1", "sizes" : "L" }_id:1인 다큐먼트를 sizes 배열의 요소 갯수만큼 document로 분리함. RDBMS의 데카르트곱(카데시안곱)과 같은 동작을 함. 두번째 예제) sizes 배열의 요소의 순번 표시하기{ "_id" : 1..
db.orders.aggregate( [ { $match: { status: "A" } }, { $group: { _id: "$cust_id", total: { $sum: "$amount" } } }, { $sort: { total: -1 } }, { $limit: 2 } ], { cursor: { batchSize: 0 } } )batchSize:0 이면 데이터가 조회되는 즉시 리턴됨. 빠르게 첫번째 데이터를 가져올 수 있음
Aggregate 예제1보다 몽고쉘에서 수행하는 형태로 작성해 보기....new Document 방식 보다는 아래 방식이 더 비슷해 보입니다. MongoClient mongo = ~~~ 생략... MongoDatabase db = mongo.getDatabase("test"); // test db MongoCollection coll_trd = db.getCollection("tn_trade"); AggregateIterable res_doc = coll_trd.aggregate ( Arrays.asList( Aggregates.match( Filters.gte("price", 50000) ), Aggregates.group("$prdt_nm", sum("tot_sum", "$price") ) )); f..
MongoClient mongo = ~~~ 생략... MongoDatabase db = mongo.getDatabase("test"); // test db MongoCollection coll_trd = db.getCollection("tn_trade"); AggregateIterable res_doc = coll_trd.aggregate ( Arrays.asList( new Document("$match", new Document("price", new Document("$gte", 50000))), new Document("$group", new Document("_id", "$prdt_nm") .append("trd_sum", new Document("$sum", "$price")) )); for(..
product 콜렉션의 price 필드를 업데이트하는 예제 1. 전체 document의 price를 일괄 업데이트=> db.product.update( {}, {$set:{price:1000.5}}, {multi:true}) 2. price 값에서 소수점 제거=> db.product.find().forEach( function(data) { db.product.update( {_id:data._id}, {$set:{price: Math.round( data.price)}} ) }); * 원래 필드값을 참조해서 업데이트 하려면 2번의 경우처럼 좀 복잡하게 해야 합니다. 앞으로 현재값을 가리키는 연산자가 추가 되었으면 더 편할 듯 합니다. 2번의 경우를 자바로 구현하면 아래와 같습니다.==> 콜렉션까지 가지..
net: bindIp: 127.0.0.1 port: 50000storage: dbPath: /Users/moonsun/mongodb/data/db engine: wiredTiger directoryPerDB: true wiredTiger: engineConfig: cacheSizeGB: 1 directoryForIndexes: true statisticsLogDelaySecs: 0 collectionConfig: blockCompressor: snappy indexConfig: prefixCompression: true journal: enabled: truesystemLog: destination: file path: /Users/moonsun/mongodb/data/log/mongod.log quie..
- Total
- Today
- Yesterday
- VARIDESK
- 파나소닉 비데 DL-EH10KWS
- Sybase IQ
- JMW 헤어드라이기기
- 별잉 빛나는 밤
- 유가바이트디비
- 톡토기
- 오미크론
- Pixel Pals
- 빈센트 반 고흐
- 배당급
- node.js
- 코라나 19
- Life Chair
- weka
- 화분벌레
- 로니카 BCS
- 고체 향수
- 홈 오피스
- 브리다 정수기
- 솔리드 쿨론
- 르세라핌
- yugabyteDB
- GKRS
- 증권정보포털
- 남설 팔찌
- 매직 트랙패드2
- 카카오 에드
- 루미큐브 종류
- 별이 빚나는 밤
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |