반응형
String update_aggregation_query = "[" +
" {" +
" \"$match\": {" +
" \"{{Field name}}\": \"" + {{Value}} + "\"" +
" }" +
" }, {" +
" \"$addFields\": " + {{update할 field와 value}} +
" }, {" +
" \"$merge\": {" +
" \"into\": \"{{Collection name}}\", " +
" \"on\": \"{{Primary Key}}\", " +
" \"whenMatched\": \"merge\", " +
" \"whenNotMatched\": \"fail\"" +
" }" +
" }" +
"]";
- addFields : 새로운 field 추가할 때 사용하며, 기존 field와 이름이 같은 경우 기존 값만 변경됨
- merge : 파이프라인의 마지막 단계
-> whenMatched: <replace|keepExisting|merge|fail|pipeline>
-> whenNotMatched: <insert|discard|fail>
반응형
'mongo db' 카테고리의 다른 글
[MongoDB] findOneAndUpdate 사용법 (0) | 2022.12.28 |
---|---|
[MongoDB] 기본적인 쿼리(DB, Collection, Document) (0) | 2022.10.25 |
[Spring] Jackson 라이브러리로 데이터 필터링하기 (0) | 2022.10.19 |