0
이 두 문서 아래 고려 발생 카운트 :그룹 배열 요소가
{ "name" : "test1", "source" : ["Apple","Cherry"], "dest" : ["Banana", "Durian"]}
{ "name" : "test2", "source" : ["Melon","Fig"], "dest" : ["Apple"]}]
입력
["Apple","Orange","Fig"]
예상 출력
{ "_id" : "Apple", nameList : ["test1", "test2"] }
{ "_id" : "Fig", nameList : ["test2"] }
{ "_id" : "Orange", nameList : [] }
집계
db.getCollection<name>.aggregate([
{ "$match" : <some_matching_conditions>},
{ "$project" :
{ "$project" : { "input_array" : { "$literal" : ["Apple","Orange","Fig"]} }},
{ "obj" : {"$setUnion" : ["$source", "$dest"]}},
},
{ "$unwind" : "$aray"},
{ "$match" : { "aray" : { "$in" : "$obj"}}},
{ "$group" : <grouping_conditons>}
])
오류 : "errmsg": "예외 : 잘못된 쿼리 : BadValue $에 배열이 필요합니다" – Bala