[MongoDB] 실전 쿼리 작성2
[ // 특정 필드만 include, exclude {$project: { title : 1, _id : 0 // _id는 자동 생성되는데 쓰고 싶지 않으면 0으로 추가 }}, // 특정 필드만 include, exclude // 유지보수 가독성이 떨어짐. 좋은 형태는 아님 (프로시저 유사) // 쿼리를 가져와서 클라이언트 레벨에서 처리하는 것이 좋음 {$project: { title : 1, year : 1, genres : 1, first_genre :{$arrayElemAt : ["$genres", 0]}, imdb : 1, imdb_score : { $cond : [ // 특정 값이 크다면 Excel..
2025. 6. 17.
[MongoDB] 실전 쿼리 작성
데이터 샘플{ "_id": { "$oid": "573a1399f29313caabcee864" }, "plot": "A serial adventure writer with problems in his personal life lives out the adventures of his literary hero, King of Adventurers.", "genres": [ "Action", "Adventure" ], "runtime": 91, "cast": [ "Jet Li", "Rosamund Kwan", "Charlie Yeung", "Takeshi Kaneshiro" ], "num_mflix_comments": 0, "poster": "https:/..
2025. 6. 16.
[MongoDB] 데이터 파이프라인과 Lookup
집계 함수GROUP BY, SUM , AVG, COUNT$group, $sum, $avg, $count-------$lookup$matchSELECT, AS$project, $addFields, $set------[ {$match : {status : "A"}}, {$group : {"_id" : "$cust_id", total : {$sum : "$amount"}}, {$sort : {"total" : -1}]{ "cust_id" : "A", "amount" : 3}{ "cust_id" : "B", "amount" : 10}{ "cust_id" : "A", "amount" : 3}{ "_id" : "A", "total" : 6}{ "_id..
2025. 6. 16.